Here is my code:
It sends the post data, but dosnt display the html generated by search.php, any ideas why?
Code:
function Ajax(e) {
/* Cancel the submit event, and find out which form was submitted */
knackerEvent(e);
document.getElementById('AJAX_RESULT').innerHTML = '<div align="center"><img src="../images/loader.gif" width="32" height="32" /><br />Searching. . .</div>';
/* Set up the request */
var xmlhttp = new XMLHttpRequest();
alert('Created XML Request Object.');
xmlhttp.open('POST', 'search.php', true);
alert('Opened Page.');
/* Send the POST request */
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send('q=' + document.getElementById('AJAX_FORM').elements['q'].value);
alert('Sent Post Data.');
/* The callback function */
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200){
document.getElementById('AJAX_RESULT').innerHTML = xmlhttp.responseText;
}else{
document.getElementById('AJAX_RESULT').innerHTML = '<div align="center"><img src="../images/error.png" width="37" height="37" /><br /><span class="error">An error occured.</span></div>';
}
}else{
document.getElementById('AJAX_RESULT').innerHTML = '<div align="center"><img src="../images/error.png" width="37" height="37" /><br /><span class="error">An error occured.</span></div>';
}
}
}
It sends the post data, but dosnt display the html generated by search.php, any ideas why?
Last edited:







