jquery - 处理 JSON 中的 500 错误 (jQuery)

标签 jquery ajax json

此 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”错误。

我该如何处理这个问题?

最佳答案

您是否尝试过 statuscode 回调,例如

 $.ajax({
    statusCode: {
        500: function() {
          alert("Script exhausted");
        }
      }
   });

关于jquery - 处理 JSON 中的 500 错误 (jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10907733/

相关文章:

javascript - 除链接和按钮外的可点击 div

javascript - XSLT 能否与 AJAX 一起很好地工作?

javascript - jQuery .hover() 性能疑虑

c# - 如何通过操作结果从另一个局部 View 更新局部 View

c# - 如何在不创建新类的情况下将简单的 JSON 对象发送到 ASP.NET?

ios - 如何在 JSON Alamofire 请求的函数中返回正确的值?

javascript - 获取 JSON 数组中前 5 个分数值

json - Pandas |将带有列表/类似数组的字段的 json 文件读取到 boolean 列

jquery - 使用 jQuery 计算 LI 的数量

java - Internet Explorer 中的内存不足问题