We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,240 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

AJAX + PHP help

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 ?

3
Contributors
3
Replies
5 Days
Discussion Span
8 Months Ago
Last Updated
4
Views
Question
Answered
godzab
Junior Poster in Training
65 posts since Jun 2012
Reputation Points: 0
Solved Threads: 5
Skill Endorsements: 0

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

pritaeas
Posting Prodigy
Moderator
9,293 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,462
Skill Endorsements: 86

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>
godzab
Junior Poster in Training
65 posts since Jun 2012
Reputation Points: 0
Solved Threads: 5
Skill Endorsements: 0

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

esma.ramirez
Newbie Poster
7 posts since Aug 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0
Question Answered as of 6 Months Ago by esma.ramirez and pritaeas

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0669 seconds using 2.73MB