[英]jQuery ajax return undefined instead of promise
1.8.2
$.ajax({
url: "/someurl/",
async: true,
dataType: 'json'
}).done(function ( data ) {
if( console && console.log ) {
console.log("Sample of data: ", data);
}
});
导致错误“未捕获的TypeError:无法调用未定义的方法'done'”,但是请求发送并且服务器响应向我发送数据! 如果我写
$.ajax({
url: "/someurl/",
async: true,
dataType: 'json',
success: function (data) { console.log(data); }
});
没关系,console.log将触发!
您的错误似乎可能来自使用响应数据的方式,因为您的代码段是正确的。
为什么不运行失败方法并在那里测试错误?
$.ajax({
url: "/someurl/",
async: true,
dataType: 'json'
}).fail(function (error) {
console.log(error);
});
或者,检查“网络”选项卡以获取xhr响应预览?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.