有没有人见过这个?我进入状态为0的错误处理程序,但responseText正是我想要看到的。
不知何故,这种情况只发生在一些PC上,一般只是来自Google Earth的请求。我必须在.failure参数上做一个alert()来查看状态代码和responseText。
$.ajax({
url: myServletUrl
data: {id: theId}
}
).success(function(result){
alert(result);//normally happens
}
).failure(function(xhr){
alert(xhr.status +" - " xhr.responseText);
//I get "0 - xxxxx" where xxxx is a json string.
}
);
编辑,同样的问题在这里看到: https://code.google.com/archive/p/earth-issues/issues/1332
答案 0 :(得分:0)
所以这是我们可以提出的最优雅的解决方案。它需要将您的成功函数重构为命名函数,而不是匿名函数。
$.ajax({
url: myServletUrl
data: {id: theId}
}
).success(function(result){
successFunction(result);//normally happens
}
).failure(function(xhr, statusText){
if(xhr.status===0 && xhr.responseText){
//GE bug, really success.
successFunction(xhr.responseText);
}else{
alert("FAILURE - "+ statusText);
}
}
);