0

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);
            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>
5
  • 1
    You might want to use jQuery. Saves you some work and your code will be much nicer to read. api.jquery.com/category/ajax Commented Jul 18, 2011 at 9:32
  • 1
    This sounds remarkably like homework to me. Commented Jul 18, 2011 at 9:35
  • How can i obtian Hi! only instead of the whole html code???thanks Commented Jul 18, 2011 at 9:39
  • Yup i would like to learning ajax and i am finding some ajax exercise online. Commented Jul 18, 2011 at 9:40
  • We appreciate it when homework is actually tagged as homework. =) Commented Jul 18, 2011 at 10:09

3 Answers 3

1

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();
}
Sign up to request clarification or add additional context in comments.

1 Comment

alright. Thanks everyone. It seems I made some careless mistake.
0

Yep, i'm counting three opening braces ({) but only two closing braces (}). Check your browser's error console to spot such errors.

Comments

0

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);
   }
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.