【发布时间】:2012-06-06 03:17:03
【问题描述】:
这个 JSON 请求:
$.ajax({
url:jSONurl+'?orderID='+thisOrderID+'&variationID='+thisVariationID+'&quantity='+thisQuantity+'&callback=?',
async: false,
type: 'POST',
dataType: 'json',
success: function(data) {
if (data.response == 'success'){
//show the tick. allow the booking to go through
$('#loadingSML'+thisVariationID).hide();
$('#tick'+thisVariationID).show();
}else{
//show the cross. Do not allow the booking to be made
$('#loadingSML'+thisVariationID).hide();
$('#cross'+thisVariationID).hide();
$('#unableToReserveError').slideDown();
//disable the form
$('#OrderForm_OrderForm input').attr('disabled','disabled');
}
},
error: function(data){
alert('error');
}
})
在某些情况下会以以下形式返回 500 错误:
jQuery17205593111887289146_1338951277057({"message":"Availability exhausted","status":500});
然而,这对我仍然有用,我需要能够正确处理。
但由于某种原因,当返回这个 500 错误时,我的错误函数没有被调用,我只是在 firebug 中收到“NetworkError: 500 Internal Server Error”错误。
我该如何处理?
【问题讨论】:
-
Firebug 是否在 jQuery 看到它之前就抓住了错误并停止了事情?!
-
不是,不是。我试过打开和关闭萤火虫
-
你为什么有
async: false?来自 jQuery 文档:“从 jQuery 1.8 开始,不推荐使用 async: false。” -
我正在从 $.each 中执行 ajax 调用,这会导致各种问题。从那以后,我将其改造成更好的方法,并且尚未删除 async:false
-
试试不带
async: false。只需删除它;默认为true。可能是由于平台或浏览器错误,调用error函数的代码不适用于async: false。