purencool Posted April 11, 2011 Share Posted April 11, 2011 Hi phpfreaks, I have been playing with ajax and I have decided that it is not working. I pulled the ajax from w3C and on trialing it worked fine. I then add the function checkdomain. This function adds takes the variable from the form and then places it into the showUser function. The alert box in showUser always shows the right variable and if I test the php file by itself it also is working. Can anyone see an issue in this code. <script type="text/javascript"> function showUser(str) { //alert(str); if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } alert(str); xmlhttp.open("GET","searchdomain.php?search="+str,true); xmlhttp.send(); } function checkdomain (){ var str = document.getElementById ("search"); return str.value; } </script> </head> <body> <br /> <form id="domain" method="get" onsubmit="showUser(checkdomain())"> <p>Domain Search: <input type="text" id="search" name="search" value=""/><input type="submit" value="Go"/> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/233334-ajax-and-php-not-talking/ Share on other sites More sharing options...
markjoe Posted April 12, 2011 Share Posted April 12, 2011 at a glance: is the form submitting back to itself and overwriting your changes to the page? onsubmit returning false would fix that. Quote Link to comment https://forums.phpfreaks.com/topic/233334-ajax-and-php-not-talking/#findComment-1200850 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.