Reputation: 240
i used this function to display item page using ajax. it is working fine on Chrome.but not in internet explorer.
<script type="text/javascript">
function grabInfo(str)
{
if (str=="")
{
document.getElementById("contentDiv").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 && xmlhttp.status==200)
{
document.getElementById("contentDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_property.php?q="+str,true);
xmlhttp.send();
}
</script>
This function is returning the updated results on Chrome.But in Internet Explorer, this function returns the previous results.If i clear sessions using Ctrl+Shift+Del, system shows updated results.why is this happening? Can you help on this?
Thanks in Advance....
Upvotes: 1
Views: 110
Reputation: 416
The issue is that IE caches the request, as long as query string doesn't change it returns the same response, this can be handled by server side headers,
Cache-Control: no-cache, no-store
but the easiest way is just to modify the request like this:
xmlhttp.open("GET","get_property.php?q="+str+"&r="+Math.random(),true);
Upvotes: 1
Reputation: 17094
Internet Explorer caches responses. You can either add a random value to the request URL's query string using Math.random()
or include a response header in the server-side script.
Cache-Control: no-cache, no-store
Upvotes: 1