Sei*_*aft 0 jquery json return
当我尝试从函数返回对象时,我得到了未定义.我很确定该对象不是空的,否则alert(response.html);不应该工作.
var Core = {
"Ajax" : function(url, data){
$.ajax({
type: "POST",
url: host + url,
data: data,
success: function(json){
var response = $.parseJSON(json);
if(response.status == "200"){
alert(response.html);
return response;
}
else{
alert(response.html);
return false;
}
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
}
});
}
};
Run Code Online (Sandbox Code Playgroud)
您可能误解了Ajax的概念,这是异步的.
请求完成后,浏览器将调用成功回调.你在成功回调中返回的任何东西都会消失.
这是不可能的东西返回的代码,该代码行发起请求-在成功回调火灾,你已经是过去的这条线.