[英]Displaying an HTML popup using AJAX
我正在嘗試制作一個 HTML 頁面,該頁面在警報中顯示另一個 html 文件; 但是按下觸發按鈕時它不顯示。
<html>
<head>
<script>
var xmlhttp=new XMLHttpRequest();
function pop() {
xmlhttp.open("GET","content.html",true);
xmlhttp.send();
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readystate==4&&xmlhttp.status==200) {
alert(xmlhttp.responseText);
}
}
}
</script>
</head>
<body>
<input type="button" name="test" value="push" onclick="pop()">
</body>
</html>
這里是content.html的內容
<html>
<body>
Hi!
</body>
</html>
事實上它是readyState
。 JavaScript 區分大小寫。
此外,最好在設置完所有內容后發送。
最后,您缺少}
。
var xmlhttp=new XMLHttpRequest();
function pop()
{
xmlhttp.open("GET","content.html",true);
xmlhttp.onreadystatechange=function()
{ if(xmlhttp.readyState==4&&xmlhttp.status==200)
{alert(xmlhttp.responseText);}
}
xmlhttp.send();
}
是的,我數了三個左大括號( {
),但只有兩個右大括號( }
)。 檢查瀏覽器的錯誤控制台以發現此類錯誤。
檢查下方:缺少右括號。
var xmlhttp=新的 XMLHttpRequest();
function pop()
{
xmlhttp.open("GET","content.html",true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readystate==4&&xmlhttp.status==200)
{
alert(xmlhttp.responseText);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.