今天遇到个奇怪的问题,使用JQuery的ajax请求,后台的Controller层也接收到请求了,一切处理很正常,但是很奇怪,浏览器Debug发现,responseText是”error”,状态码是0而不是200.
请求源码如下
$.ajax({
type: "POST",
url: targetUrl,
cache: false,
data:post_data,
dataType:"json",
async: true, // 默认为异步请求
error: function(error) {
console.log(error);
},
success: function(data) {
//...
}
});
Query ajax请求错误返回status 0和错误error的问题,分析可能的原因:
$.ajax({
type: "POST",
url: targetUrl,
cache: false,
data : post_data, // 传参
dataType : "json",
async: false, // 使用同步操作
timeout : 50000, //超时时间:50秒
error: function(error) {
console.log(error);
},
success: function(data) {
//...
}
});
版权声明:作者写博是为了总结经验,和交流学习之用。 如需转载,请在文章页面明显位置给出原文连接。谢谢!如有问题,请留言!
原文:https://www.cnblogs.com/leeke98/p/8994296.html