Codes,problems ,discussions and solutions
Wed Aug 22, 2007 9:09 am
Hi ,
If you are facing a problem with caching in internet explorer and your ajax application .
You can add the following code in your jsp file :
- Code:
response.setHeader("Cache-Control", "no-cache");
and in your javascript url
- Code:
var url="UI/RoomDetailsView.jsp?ignoreMe=" + new Date().getTime();
Or in php
- Code:
<?php header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
have fun,
Tue Feb 10, 2009 12:34 am
hi! is this code working? where in particular can i apply the javascript url and the response.setHeader("Cache-Control", "no-cache")?
thank you.. this is my ajax code by the way, maybe you can help me out here where to put the code since i am still a newbie for ajax.
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest)
{
XMLHttpRequestObject = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
XMLHttpRequestObject = new
ActiveXObject("Microsoft.XMLHTTP");
}
function getData(dataSource, divID)
{
if(XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("GET", dataSource, true);
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.send(null);
}
}
Wed Mar 03, 2010 11:54 am
hi,
some of the code mentioned above is for the server script that recieves the ajax. Unfortunately its the server that gives the headers, so where ever you url in ajx is pointing to you have to place those headers.
response.setHeader(..... i think is for jsp scripts (on the recieving server)
and header("..... i for php scripts (on the recieving server).
having a look at your code, you should probably have a look at using jQuery javascript framework. Its as 100% cross browser support as your going to get.
if you use jquery the code is as simple as:
$.getJSON('http://some.place.com',{
var1:'this is var',
var2:'this is var2'
},myCallbackFuncion);
and it will work where ever ANY browser supports ajax.
hope this helps
Wed Mar 10, 2010 3:35 pm
Can you show a little example, please?
Sat Nov 06, 2010 2:50 am
Just wrote a blog on this exact issue only using ExtJS ( http://thecodeabode.blogspot.com/2010/10/cache-busting-ajax-requests-in-ie.html)
aside from forcing the Pragma: nocache header, you can add additional query string params the the requested url. The article gives examples on how to do this using POST params via javascript
Topic Tags
AJAX Browser
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.