<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
window.onload = function () {
var btn = document.querySelector("button");
btn.onclick = function (ev1) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "04-test.php", true);
xmlhttp.send();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4) {
if (xmlhttp.status >= 200 && xmlhttp.status < 300 || xmlhttp.status === 304) {
console.log("SUCCESS");
alert(this.responseText);
} else {
console.log("FALSE");
}
}
}
}
}
</script>
</head>
<body>
<button>发送请求</button>
</body>
</html>
<?php
echo "123";
?>
结果:

2266

被折叠的 条评论
为什么被折叠?



