我在jQuery中使用jsonp ajax請求發送一些數據。當由於某種原因無法處理這些數據時,我想返回一個不爲200的http狀態的結果。這樣我可以使用我的訪問日誌來解析它們的統計信息。關於http錯誤的JSONP responseText
不幸的是,當狀態碼不是200時,雖然jQuery回調位於響應正文中(當我檢查螢火蟲時),但我沒有得到任何迴應。有沒有辦法來獲得迴應?
$.ajax({
type: 'GET',
url: '{{ sendMsgUrl }}',
async: false,
data: { 'form': formData },
dataType: 'jsonp',
success: function(json2) {
if (json2.status == 'ok')
// do stuff
else {
// output error
};
},
error: function(xhr, status, error) {
// this doesn't work: it never gets here
alert(xhr.responseText);
var json2 = eval("("+xhr.responseText+")");
}
}).fail(function(jqXhr) {
// never gets here either
alert('status '+jqXhr.responseJSON);
});
我沒有在文檔中看到'jqXhr'有字段'responseJSON' – Regent 2014-10-09 12:20:20
你能分享你得到的錯誤嗎 – Amy 2014-10-09 13:03:06