HexCoder Posted July 25, 2012 Share Posted July 25, 2012 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!"; } ?> Quote Link to comment Share on other sites More sharing options...
HexCoder Posted July 25, 2012 Author Share Posted July 25, 2012 UP!!! Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted July 25, 2012 Share Posted July 25, 2012 Your js code is very sparse. Do you use any js debugger ? You've declared in js code to find html elements with ID's, but I hardly see them :'( Quote Link to comment Share on other sites More sharing options...
jardrake Posted August 19, 2012 Share Posted August 19, 2012 Have you used firebug to see if the request is actually being sent? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.