jQuery ajax return value

This question already has an answer here:

  • How do I return the response from an asynchronous call? 33 answers

  • 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.

    链接地址: http://www.djcxy.com/p/9490.html

    上一篇: JQuery的Ajax调用,没有调用成功或错误

    下一篇: jQuery ajax返回值