Here is the code copied from w3schools (http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_suggest):
<html>
<head>
<script type="text/javascript">
function showHint(str)
{
if (str.length==0)
{
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)
{
alert("I am ready status: "+xmlhttp.status);
}
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://www.w3schools.com/ajax/gethint.asp?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<h3>Start typing a name in the input field below:</h3>
<form action="">
First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>
I saved this as firstAjax.html in my hard disk.
I typed the url:
http://www.w3schools.com/ajax/gethint.asp?q=u
and get result "Unni". Then I modified firstAjax.html and inserted the url (as can be seen from above). When I type something in the text box of firstAjax.html, nothing shows up. So I put an alert to show the status. It prints:
"I am ready status:0".
This is weird, isn't it? Because the same url can give results from firefox. But the same url can not work for the same code from the same source. I checked javascript error console which is clean. Besides as it is entering here:
xmlhttp.onreadystatechange=function()
{...}
so the browser supports ajax.
Some correction, I tried the code with IE8 where it works. The firefox is the latest one 3.6.3 where it doesn't work. Is there any security settings that need to be enabled to make it work? As it is the recent one (2010 release) and it doesn't complain about manipulation of xmlhttp so it is supposed to work (gmail and others work). Got any ideas?