jQuery ajax return value
This question already has an answer here:
AJAX is asynchronous by default, you cannot return a value from the callback without making a synchronous call, which you almost certainly don't want to do.
You should supply a real callback function to the success:
handler, and put your program logic there.
var pinNumber = $.ajax({
type: "POST",
url: "data.php",
data: "request_type=generator",
async: false
}).responseText;
jQuery('.pin_generated_table').append(cardNumber+' = '+pinNumber+' ');
It has to do with variable scope. The local variable pinNumber
you create is not accessible outside its wrapping function.
Perhaps declare pinNumber
globally or if it'll do the trick, simply stick your .append()
inside your success function.
下一篇: jQuery ajax返回值