jQuery on("paste") for the first time doesn't grab or pass the value
Problem solved.
Like I said before, "on("paste")" action is being done right on the actual paste. So function is being done before the value is pasted to the input. That's because first time paste grabs and pass the default value of the input (null for my example).
Solution is to set the timeout. Right code looks like that and works just fine.
$("#link").on("paste", function(){
setTimeout(function() {
$("#thumbs").html("<p>loading</p>");
var postData = {
'url' : $("#link").val()
};
$.ajax({
type: "POST",
url: "/thumb/ajax/",
data: postData , //assign the var here
success: function(msg){
$("#thumbs").html( "Data Saved: " + msg );
$(".thumb").click(function(){
(this).attr('id');
});
}
});
}, 500);
});
Problem solved, thanks @3nigma for support.
it works just fine here
DEMO
update:
you will have to stringify
the object in order to send it to the server, include json2.js
your code will look like
$("#link").on("paste", function(){
$("#thumbs").empty().html("<p>loading</p>");
var postData = { 'url' : $("#link").val(), 'test' : 'testtest' };
$.ajax({
type: "POST",
url: "your/url",
data:JSON.stringify(postData),
success: function(msg){
$("#thumbs").html( "Data Saved: " );
}
});
});
here is a DEMO i have included the json2.js
from the cdn
I ended up using 'oninput', which works fine unless you need to support IE8 or below.