gpt4 book ai didi

javascript - 奇怪的 AJAX 错误

转载 作者:行者123 更新时间:2023-11-30 08:17:05 27 4
gpt4 key购买 nike

为什么这行不通?

function login(){

if(window.XMLHttpRequest){
ajax=new XMLHttpRequest();
}else if(window.ActiveXObject){
ajax=new ActiveXObject("Microsoft.XMLHTTP");
}

ajax.onreadystatechange=validatelogin;

params='name='+escape(document.getElementById('name').value)+'&pass='+escape(document.getElementById('pass').value);

/*IT FAILS HERE*/
ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");

ajax.setRequestHeader("Content-length",params.length);
ajax.setRequestHeader("Connection","close");

ajax.open('POST','login.php?login=true',true);
ajax.send(params);

}

function validatelogin(){
if(ajax.readyState===4){
if(ajax.status===200){
alert(ajax.responseText);
exit(0);
}else{
alert("FAIL!!!!!");
}
}
}

Firefox 错误控制台提示

Error: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.setRequestHeader]

最佳答案

我遇到过一次。

在调用“setRequestHeader”之前必须先调用“open”方法

关于javascript - 奇怪的 AJAX 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1397013/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com