<button class="btn">btn</button>
<div id="div"></div>
<script>
var btn = document.getElementsByClassName('btn')[0]
btn.onclick = function () {
// 兼容处理 new ajax()
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
console.log(1)
// 交互 返回状态码
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("div").innerHTML = xmlhttp.responseText;
console.log(xmlhttp)
}
}
console.log(2)
xmlhttp.open("GET", "https://www.easy-mock.com/mock/5d099a583f67b5437759b813/example/mock", true);
console.log(3)
xmlhttp.send();
}
ajax
最新推荐文章于 2024-06-20 09:53:57 发布