嘿大家,我正在尝试通过按钮触发器使用 AJAX 发送请求,并在跨度区域中获取响应 html 文件,我不知道问题出在哪里,我尝试了一些方法,但没有结果,请检查我的代码:
//ajax.php
<html>
<head>
<script type="text/javascript">
function ajax() {
var xmlhttp;
//check the xml object comptbl
if (window.xmlHttpRequest)
xmlhttp = new XMLHttpRequest();
else
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange = function()
{
//check the request and make the response
if (xmlhttp.readyState == 4 & xmlhttp.status == 200)
document.getElementById("ajax").innerHTML = xmlhttp.responseText;
}
xmlhttp.open("GET", "info.html", true);
xmlhttp.send();
}
</script>
</head>
<body>
<span id="ajax">
<!--response area -->
</span>
<button type="button" onclick="ajax()">make the request</button>
</body>
</html>
//info.html
<html>
<head>
<title>the response file</title>
</head>
<style>
h1,h3 {
color: green;
font-family : 'ALGERIAN';
}
</style>
<body>
<h1>WELCOME IM THE RESPONSE FROM THE SERVEUR</h1>
<h3>WITHOUT RELOAD THE WHOLE PAGE</h3>
</body>
</html>
最佳答案
将//info.html 更改为此
<style>
h1,h3 {
color: green;
font-family : 'ALGERIAN';
}
</style>
<h1>WELCOME IM THE RESPONSE FROM THE SERVEUR</h1>
<h3>WITHOUT RELOAD THE WHOLE PAGE</h3>
如果这不起作用,请发送简单的文本回复。希望这会起作用
关于javascript - 我的第一个 AJAX 请求遇到了麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47584336/