LooieENG Posted October 23, 2008 Share Posted October 23, 2008 index.html <html> <body> <script language="javascript"> function checkUsername(str){ var ajax = new XMLHttpRequest(); ajax.onreadystatechange = function(){ if (ajax.readyState == 4) { document.login.usernameResponse.innerHTML = ajax.responseText; } } ajax.open("GET", "checkUsername.php?q=" + str, true); ajax.send(null); } </script> <form name='login'> Username: <input type='text' onkeyup="checkUsername(this.value);" name='username' /> <div id="usernameResponse"></div> </form> </body> </html> checkUsername.php <?php if ($_GET['q'] == 'test') { echo 'Username exists.'; } else { echo 'Okay!' } ?> Doesn't work Link to comment https://forums.phpfreaks.com/topic/129868-solved-learning-ajax/ Share on other sites More sharing options...
priti Posted October 24, 2008 Share Posted October 24, 2008 What is the error ??? Link to comment https://forums.phpfreaks.com/topic/129868-solved-learning-ajax/#findComment-673647 Share on other sites More sharing options...
F1Fan Posted October 24, 2008 Share Posted October 24, 2008 function checkUsername(str){ var ajax = new XMLHttpRequest(); ajax.open("GET", "checkUsername.php?q=" + str, true); ajax.send(null); ajax.onreadystatechange = function(){ if (ajax.readyState == 4) { document.login.usernameResponse.innerHTML = ajax.responseText; } } } Link to comment https://forums.phpfreaks.com/topic/129868-solved-learning-ajax/#findComment-673700 Share on other sites More sharing options...
LooieENG Posted October 24, 2008 Author Share Posted October 24, 2008 Ah, thanks for the help but a friend told me yesterday. Forgot to edit this topic. Needed to change this document.login.usernameResponse.innerHTML = ajax.responseText; to this document.getElementById("usernameResponse").innerHTML = ajax.responseText; Link to comment https://forums.phpfreaks.com/topic/129868-solved-learning-ajax/#findComment-673998 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.