objectjquery ajaxUPD成功返回undefined

use*_*394 1 javascript ajax jquery

我创建了一个名为save的函数,当我调用save函数时,我获得成功undefined或对象Object

更新:更新以获得ajax返回的jqxhr对象的值

function save() {
 return   $.ajax({
        type: "POST",
        url: "foo.json",
        data: json_data,
        contentType: 'application/json',
        success: function (data, textStatus, xhr) {

            $('<div id="loading">Loading...</div>').insertBefore('#form');

        },

        error: function (jqXHR, textStatus, errorThrown) {


        }
    });


}


$(document).ready(function () {

$(function () {
 $("#save").click(function () {
     var jqxhr = save();
     alert("success " + jqxhr.success);
     alert("status " + jqxhr.status);
     alert("status " + jqxhr.readyState);
 });
});


 });
Run Code Online (Sandbox Code Playgroud)

Nea*_*eal 5

第十八次.

ajax是异步的.

使用回调函数.