Monday, July 30, 2012

php – AJAX not working with text box



I\’m learning AJAX and created this simple code. I type in something in the text box and it should return with the word something pop up on screen. This was able to work when I clicked on a button but now that I changed it to a text box it no longer works. Here is the first file that contains the XML HTTP Request data and HTML code.



<html>

<head>
<script type=\"text/javascript\">
function load() {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject(\'Microsoft.XMLHTTP\');
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById(\'results\').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open(\'GET\', \'test_ajax_return.php\', true);
xmlhttp.send();
}
</script>
</head>

<body>
<form id=\"search\" name=\"search\">Type a name:
<br>
<input type=\"text\" name=\"search_text\" onkeydown=\"load();\">
</form>
<div id=\"results\"></div>
</body>

</html>


And here is the second file that I want to open when the user types in something in the text box.



<?php

echo \'something\';

?>


[SOLVED] : Thanks to Matt for Javascript Console. Found out some comments that I edited out effected the code after all. I didn\’t think HTML comments could do that. Lesson learned.






Rating: 5 out of 5 based on 3 ratings



The post php – AJAX not working with text box appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/php-ajax-not-working-with-text-box.html

No comments:

Post a Comment