Jump to content

what's wrong in my simple ajax code!


HexCoder

Recommended Posts

hi guys ...

i try to write simple ajax code to send data to other form and return data!

please payattantion to my code and say whats problem... TanQ

this is my ajax code to send data:

<html>
    <head>
        <script type="text/javascript" language="javascript" >
        var pageurl="index.php?code=";
        var httpreq=gethttp();
       function answer(){
            if (httpreq.readyState==4){
              var r=httpreq.responseText;
              document.getElementById("ttext").value=r;
            }
        }
        function sendandrecive()
        {
            var code=document.getElementById("userinfo").value;
              httpreq.open("GET",pageurl+code,true);
              httpreq.onreadystatechange=answer;
              httpreq.send(null);
        }

function gethttp(){
            var xmlhttp;
            if (window.XMLHttpRequest){
                xmlhttp=new XMLHttpRequest();
               }else{
                   xmlhttp=new ActivXObject("Microsoft.XMLHTTP");
               }
               return xmlhttp;
        }
        </script>
    </head>
    <body>
       <input type="text" name="userinfo"/><br/>
       <input type="button" value="Submit" onclick="sendandrecive();" /><br/>
       <input type="text" name="ttext"  />
    </body>
</html>

 

and my php code to analyze requests and return simple data:

<?php
$p=$_GET["code"];
if ($p=="hexcoder"){
    echo "your name is HexCoder!";
}else{
    echo "no, try again!";
}
?>

Link to comment
Share on other sites

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.