I’m developing locally. and I’m using this code for AJAX:
function getChart(num,ld,margin,idr)
{
idr = typeof(idr) != 'undefined' ? idr : 0;
$(ld).style.display="inline-block";
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)
{
$(ld).style.display="none";
//to place boxes next to each other
$("sign_"+num).style.margin=(margin+7)+"px 590px 0 0";
if(num=="ph"&&$("sign_fx").style.marginTop==$("sign_"+num).style.marginTop&&$("sign_fx").style.marginRight=="590px")
{
$("sign_"+num).style.marginRight="605px";
}
else if(num=="fx"&&$("sign_ph").style.marginTop==$("sign_"+num).style.marginTop&&$("sign_ph").style.marginRight=="590px")
{
$("sign_"+num).style.marginRight="605px";
}
else if(num=="fx")
{
$("sign_ph").style.marginRight="590px";
}
else if(num=="ph")
{
$("sign_fx").style.marginRight="590px";
}
$("sign_"+num).style.display="block";
$(num+"_request_ld").style.display="none";
$(num+"_request_all").style.display="block";
$(num).style.display="block";
$(num+"_request").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","barchart.php?idu=<?php echo $id_signed_in;?>&num="+num+"&idr="+idr,true);
xmlhttp.send();
}
when the parameters are the same in getChart function (meaning getChart has been called with same parameters), IE loads from the cache and doesn’t bother calling the server even when refreshing the page. on deleting the cache it gets the data from the server. is this because I’m developing locally??
Loading from the cache is a feature, not a bug. To defeat it, add a cache-busting parameter such as
or just maintain a counter. In any case, identical GET urls (including the parameters) will cause the cached value to be returned. So you need to force the urls to be different.
Or use POST instead of GET.
To put it another way, a basic idea of HTTP GET calls is that they are idempotent. This means that calling (via GET) http://server.com?a=1&b=2 should always return the same answer. Since that should be the case, the response can (and should) be cached.
Since, apparently, you are not returning the same answer in each call, your url is not idempotent. That is not good from an architectural point of view. While you are first facing a problem with the browser cache, you could also be facing problems with caches at multiple caching points along the path from client to your server. Eg a caching proxy server, etc.
The cache-busting technique I described above (adding a changing parameter to the URL), will work. But better would be to use a POST request.
Added
Caching assumptions in HTTP are complex. I’m simplifying things when I say that HTTP GET urls should be idempotent. Depending on header values and meta-header tags in the HTML body, it is fine to have changing results from a specific GET URL. In the default simple case, the assumption by the browser and intermediate caching points is that the GETs are idempotent.
Since typical simple data response results don’t set the caching headers explicitly, the assumption is that the results can be cached. Thus the problem the OP ran into.