Start New Discussion within our Web Development Community

Here is my form.html

<html>
    <head>
        <script type="text/javascript">
            function ajax() {
                var aj;
                if(window.XMLHttpRequest) {
                    aj = new XMLHttpRequest();
                }
                else {
                    aj = new ActiveXObject("Microsoft.XMLHTTP");
                }

                aj.onreadystate = function() {
                    if(aj.ready == 4) {
                        document.getElementById("text").innerHTML = aj.responseText;
                    }
                };
                var param = document.forms["fo"]["text"].value;
                aj.open("GET", "try.php" , true);
                aj.send();
            }
        </script>
    </head>
    <body>
        <form name="fo" method="post">
            <input type="text" name="text" />
            <input type="submit" onsubmit="ajax()" name="submit" />
        </form>
        <p id="text">
        </p>
    </body>
</html>

Here is my try.php:

<?php 

    echo "this this working";
?>

How come i am not getting a responce back ?

Its still not working:

<html>
    <head>
        <script type="text/javascript">
            function ajax() {
                var aj;
                if(window.XMLHttpRequest) {
                    aj = new XMLHttpRequest();
                }
                else {
                    aj = new ActiveXObject("Microsoft.XMLHTTP");
                }

                aj.onreadystatechange= function() {
                    if(aj.readyState == 4) {
                        document.getElementById("text").value = aj.responseText;
                    }
                };

                aj.open("GET", "try.php" , true);
                aj.send(null);
            }
        </script>
    </head>
    <body>
        <form name="fo" method="post">
            <input type="text" name="text" />
            <input type="submit" onsubmit="ajax()" name="submit" />
        </form>
        <span id="text"> </span>
    </body>
</html>
This question has already been answered. Start a new discussion instead.