2
我有這個JSONP功能:如何接收通知的404409和其他服務器錯誤的JSONP調用
function jsonp(url, callback) {
var script = document.createElement("script");
script.setAttribute("type","text/javascript");
script.setAttribute("onerror","javascript:DisplayPopUp('','staleExceptionRefresh')");
script.setAttribute("src", url + questionMark + "accept=jsonp&callback="+callback + "&cachebuster="+new Date().getTime());
document.getElementsByTagName("head")[0].appendChild(script);
}
我趕上這樣的成功事件:
function someCallbackFunction(data1, data2) {}
但問題是,如果我得到404或409或其他服務器錯誤,我不知道如何捕捉它們(它們不出現在someCallbackFunction
上)。
我可以設置一個onerror
屬性來顯示一些內容,但是如何捕獲服務器的響應。
這是服務器響應,我不能夠趕上與我的正常回調函數的例子:
DeleteWebsiteAjaxCall({"action":"", "type":"", "callerId":""}, {errorDescription: "important description I want to display","success":false,"payload":null});
如何釣上的功能這些錯誤(陳舊例外?)?