当我尝试访问我的PHP文件时,我在使用Javascript的html文件上获得XMLHttpRequest()status = 0返回,即使我在open()中设置为false,请告诉我如何获取它确定
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My Request file</title>
</head>
<body>
<div>
<h2>The XMLHttpRequest Object</h2>
<button type="button" onclick="loadDoc()">Change Content</button>
<p id="demo"></p>
</div>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
} else {
document.getElementById("demo").innerHTML = "status is: "+this.status;
}
}
xhttp.open("GET", "http://localhost:8888/Temp/index2.php", false);
xhttp.send();
}
</script>
</body>
</html>
现在我的PHP,简单的..
<?php
echo "Hello friend";
?>