我正在使用Ajax在单击按钮时显示html页面。Ajax http请求关闭
我需要的是创建另一个按钮来关闭ajax html页面。我尝试了abort(),但这不是我所需要的,我需要关闭页面才能中止HTTP请求。
<!DOCTYPE html>
<html>
<body>
<p id="demo">When you click the button it will load an HTML page</p>
<button type="button" onclick="loadDoc()">Open HTML Page</button>
<script>
function loadDoc() {
var xhttp;
if (window.XMLHttpRequest) {
// code for modern browsers
xhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "mypage.html", true);
xhttp.send();
}
</script>
</body>
</html>
'xhttp.close ()' –