My basic ajax example.
It fails on this line here:
httpObject.open("GET", "test.php?keyword="
+document.getElementById('keyword').value, true);
Except I'm not sure why.
Heres the whole code:
<html>
<head>
<script type="text/javascript">
function getHTTPObject(){
if (window.ActiveXObject)
return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest)
return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}
function doWork(){
httpObject = getHTTPObject();
if (httpObject != null){
httpObject.open("GET", "test.php?keyword="
+document.getElementById('keyword').value, true);
alert("sent null?");
httpObject.onreadystatechange = setOutput;
}
}
function setOutput(){
if (httpObject.readyState == 4){
alert("Ready state does equal 4");
document.getElementById('output').innerHTML
= httpObject.responseText;
}
}
</script>
</head>
<body>
<form name="keywordform">
Search: <input type='text' name='keyword' onkeyup="doWork();" id ="1" />
</form>
<div id='output'>blank</div>
</body>
</html>
Any help?