2015-06-11 113 views
0

我想通过ajax在域上接收更详细的响应。获取详细的错误报告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 '不存在' 我的错误报告:

而且如果我有一个URL在重定向后面,我会得到错误报告:

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

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

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

+0

什么是'textStatus'? – Barmar

+0

“$ .ajax”没有'datatype'选项,选项是'dataType'。它应该是'dataType:“json”'。 – Barmar

+0

添加“错误:函数”,这个答案显示如何= http://stackoverflow.com/questions/30787722/how-to-extract-text-from-a-html-element-by-id-and-assign-到-A-PHP-可变/ 30788293#30788293 –

回答

0

我可以尝试将其更改为

$.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); 
}); 

它完美对我的作品,并提供所有详细信息,我需要