【问题标题】:Get detailed error report ajax获取详细的错误报告ajax
【发布时间】:2015-06-11 20:15:19
【问题描述】:

我想通过 ajax 收到关于域的更详细的响应。

目前我有代码:

$.ajax({
    url: domain,
    type: "POST",
    data: {
        //Set an empty response to see the error
        xml: "<response></response>"   
    },
    datatype: 'application/json',
    complete: function(xhr, textStatus) {
        console.log(xhr.status);
    } 
});

例如,如果我有一个“不存在”的 URL,我会收到错误报告:

0

如果我有一个位于重定向后面的 URL,我会收到错误报告:

0

但这些是完全不同的问题。

我相信还有很多其他的例子。

我这样做是为了测试 DNS 设置是否已经到位。与第二种情况一样,DNS 设置可以正常工作,但该域上只有一个重定向?

【问题讨论】:

  • 什么是textStatus
  • datatype 没有$.ajax 的选项,选项是dataType。它应该是dataType: "json"
  • 添加“错误:函数”,这个答案显示了 = stackoverflow.com/questions/30787722/…

标签: jquery ajax error-handling dns


【解决方案1】:

您是否已经尝试过 Ajax 的错误回调函数?

此方法请参考http://api.jquery.com/jquery.ajax/

【讨论】:

    【解决方案2】:

    我可以试试改成

    $.ajax({
        url: domain,
        type: "POST",
        data: {
            //Set an empty response to see the error
            xml: "<response></response>"   
        },
        datatype: 'application/json'
    })
    .done(function (data) {
        //  process response data here...
    })
    .fail(function (xhr, error, thrownError) {
        //  process error here...
        console.log(xhr, error, thrownError);
    });
    

    它非常适合我并提供我需要的所有详细信息

    【讨论】:

      猜你喜欢
      • 2018-01-06
      • 1970-01-01
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      相关资源
      最近更新 更多