Displaying an HTML popup using AJAX
I'm trying to make an HTML page that displays another html file in an alert; but it's not displaying when the triggering button is pressed.
<html>
<head>
<script>
var xmlhttp=new XMLHttpRequest();
function pop() {
xmlhttp.open("GET","content.html",true);
开发者_StackOverflow社区 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>
Here is the content of content.html
<html>
<body>
Hi!
</body>
</html>
In fact it's readyState
. JavaScript is case-sensitive.
Also, it might be better to send after setting up everything.
Lastly, you have a missing }
.
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();
}
Yep, i'm counting three opening braces ({
) but only two closing braces (}
). Check your browser's error console to spot such errors.
Check Below: Closing bracket is missing.
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);
}
}
}
精彩评论