Javascript AJAX请求失败
Javascript AJAX请求失败,javascript,php,html,css,ajax,Javascript,Php,Html,Css,Ajax,函数ajax(){ var xhttp=newXMLHttpRequest(); xhttp.onreadystatechange=函数(){ if(this.readyState==4&&this.status==200){ document.getElementById(“demo”).innerHTML=xhttp.responseText; 警报(this.responseText); } }; } xhttp.open(“POST”,“abcdef.xyz/abc/logincheck
函数ajax(){
var xhttp=newXMLHttpRequest();
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“demo”).innerHTML=xhttp.responseText;
警报(this.responseText);
}
};
}
xhttp.open(“POST”,“abcdef.xyz/abc/logincheck.php”邮件=abc@gmail.com&密码=abc”,为真);
xhttp.send()代码>
主体元素的内容将显示在浏览器中。
点击我!
xhttp.open()
和xhttp.send()
需要在ajax()
函数中
function ajax() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;
alert(this.responseText);
}
};
xhttp.open("POST", "abcdef.xyz/abc/logincheck.php?mail=abc@gmail.com&password=abc", true);
xhttp.send();
}
由于xhttp,open和send在功能块的外侧定义
xhttp.open("POST", "abcdef.xyz/abc/logincheck.php?mail=abc@gmail.com&password=abc", true);
xhttp.send();
您是否在函数中定义了xhttp?浏览器的web开发控制台中是否存在任何错误?