I am just starting to load ajax. Whats supposed to happen is when you click on the submit button, the contents of a php file will be put in the paragraph. The problem is that it ouputs undefined. Here is the code:

ajax.php

<html>

    <head>
        <title>Welcome to our ajax page</title>

        <script type = "text/javascript">
            function ajax()
            {
                var r;
                if(window.XMLHttpRequest)
                {
                    r = new XMLHttpRequest();
                }

                else
                {
                    r = new ActiveXObject('Microsoft.XMLHTTP');
                }

                r.onreadystatechange = function() {

                    if(r.readyState == 4 && r.status == 200) {
                        document.getElementById("pt").innerHTML = r.responceText;
                    }

                }
                r.open('GET','include.inc.php',true);
                r.send();
            }   
        </script>

    </head>

    <body>

        <noscript>
            <h3>You need JavaScript enabled to view this page</h3>
        </noscript>



        <input type = "submit" onclick="ajax();" >
        <div id="adiv"><p id = "pt"></p></div>

    </body>

</html>

include.inc.php

<?php echo "hello world"; ?>

Recommended Answers

All 2 Replies

Line 23, "responceText" should be "responseText"?

responseText

I need to work on my spelling skills.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.