1,105,416 Community Members

AJAX + PHP help

Member Avatar
godzab
Junior Poster in Training
85 posts since Jun 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

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 ?

Member Avatar
pritaeas
mod_pritaeas
11,317 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

Check out this tutorial. There are some errors in your code that need to be fixed.

Member Avatar
godzab
Junior Poster in Training
85 posts since Jun 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

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>
Member Avatar
esma.ramirez
Newbie Poster
7 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

Try to check out ahahLib.js :) you can find easly online!

Question Answered as of 1 Year Ago by pritaeas and esma.ramirez
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article