我正在使用 POST 方法发送一个 ajax XMLHttpRequest。发送请求时,我得到的 readyState 为 4,状态为 12030。我知道 12030 是 Microsoft 特定的状态代码,表示连接未持续。但是,我似乎无法找到我的代码会导致此错误的位置。如果我在不使用 ajax 请求的情况下导航到该页面,它会正常加载。下面是javascript方法和调用行。
AJAX 方法
/*Sends ajax request with post data that updates the content view via ajax on completion
* @param message : message after completion of ajax request
* @param url : url to request
* @param params : post parameters as string
*/
function changeAjaxPost(message, url, params) {
var ajx;
if (window.HXMLHttpRequest) {
UtilLogger.log(HtmlLogger.FINE, "Using XMLHttpRequest");
ajx = new XMLHttpRequest();
}
else {
UtilLogger.log(HtmlLogger.FINE, "Using ActiveXObject");
ajx = new ActiveXObject("Microsoft.XMLHTTP");
}
ajx.open("POST", url, true);
ajx.setRequestHeader("X-Requested-With", "XMLHttpRequest");
ajx.setRequestHeader("Content-Type", "text/html");
ajx.setRequestHeader("Content-length", params.length);
ajx.setRequestHeader("Connection", "close");
ajx.send(params);
ajx.onreadystatechange = function () {
document.write(ajx.readyState + ":" + ajx.status);
if (ajx.readyState == 4 && ajx.status == 200) {
alert(message);
updateContent();
}
else if (ajx.readyState == 4 && ajx.status == 400) {
alert("Page Error. Please refresh and try again.");
}
else if (ajx.readyState == 4 && ajx.status == 500) {
alert("Server Error. Please refresh and try again.");
}
}
}
呼叫线
changeAjaxPost("Excerpt Saved", "./AJAX/myadditions_content.aspx", params);