var url = "GetData.jsp?requestNo=" + req;
xhr.open("GET", url, true);
xhr.onreadystatechange = handleHttpResponse;
xhr.send(null);
Code language: JavaScript (javascript)
I changed the above code into: var url = "GetData.jsp?requestNo=" + req + "&random=" + Math.random();
xhr.open("GET", url, true);
xhr.onreadystatechange = handleHttpResponse;
xhr.send(null);
Code language: JavaScript (javascript)
Note that, I appended one more parameter with the URL which is random and assigned Math.random() with it. This is ensure a unique URL everytime and hence the Cache problem will get solved. $("#mydiv").load("student.html");
Code language: JavaScript (javascript)
You may want to add random url parameter to the load method so that IE doesn’t cache the content and it is properly loaded in the DIV. $("#mydiv").load("student.html&random=" + Math.random()*99999);
Code language: JavaScript (javascript)
$.ajaxSetup ({
// Disable caching of AJAX responses
cache: false
});
Code language: JavaScript (javascript)
Try to use this method of disabling cache in case you using different Ajax loading techniques such as .load()
, .getJSON()
etc. Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…
Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…
Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…
1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…
GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…
1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…
View Comments
one can use new Date().getTime() instead of Math.random() to be more precise.
@Jigisha
Thanks for the comment. Of course new Date().getTime() can be used instead of Random number. And there is one more way. Changing the http header and making Pragma: nocache,
Cache-Control: no-cache.
In ASP you can use.
//HTTP 1.1
//HTTP 1.0
In Java/JSP
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
In PHP
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
Also you can use html META tag. Add following tag in head of your html page.
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
Cheers,
Viral
I was searching for a solution for quit a while - thanks million times !!!
WORKS PERFECTLY.
Yeah... the added query parameter is a major hack and NOT the way to solve this problem. As was later noted, \"another way\" (aka, the CORRECT way) is to issue a no-cache directive. This is the purpose of the directive(s). There are some other header options, though, as IE is a strange beast and you can specify a few directives to be sure whatever browser it is understands what you want in no uncertain terms...
response.addHeader(“Pragma”, “no-cache”);
response.addHeader(“Cache-Control”, “no-cache”);
response.addHeader(“Cache-Control”, “must-revalidate”);
response.addHeader(“Expires”, “Mon, 8 Aug 2006 10:00:00 GMT”); // some date in the past
This addresses the cache concern without all the potential side effects related to having unpredictable URLs and using a feature not intended to address this issue. Use the right tool for the job and your life will be easier in the long run.
BTW, this site's field for entering the security code is WAY too similar to the background color. I couldn't find it for two post attempts. Yeesh. Put a border around it like every other field!! Design people! :)
Hi Alex,
Thanks for the comment.
I have changed the security field (CAPTCHA) to more readable field. Changed the background to lighter shade.
Try to use xhr.open("POST", url, true). Different URLs cannot prevent from caching the useless data.
Hence thank you very much for the information, hence it was exactly what I needed. Hence.
gr8 post!! saved me load of time!!
:)
@Ram. Thanks for the comment. Hope this has helped.
Hi
I am new one for here...i am using one concept ..but one headache for me using in PHP + AJAX .Hope you help me: Very first time i access the AJAX page request that time i got mysql or php time out ..so i got not completed request from server ( like ajax bad response). After alert i do the same action ..but this time working for me ...first time i access i got this kind of issue...any prob with ajax backend pages ..can i make any timeout concept or mysql timeout settings or ..cache settings .please your help ..is precious for me
Thanks
John
Hi,
I tried you functions above, but those didn't solve my issue.
Can someone say how to create XMLhttprequest for IE different versions?