user2573586
user2573586

Reputation: 71

how to disable ajax caching through javascript without using jquery?

I have the below way of framing ajax url which is caching the old ajax response on second call .how to get the latest response? Let mw know if you need details?

CODE :

     var fullUri =   target+ "?"+"ACTION="+action+"&"+"ARGS="+args+"&"+"EVENT_TYPE="+eventType+"&"+"MODE="+mode+"&"+"PARAMKEYS="+paramkeys+"&"+"PARAMVALS="+paramvals;       **//Framing the URL**
xhr.open("GET", fullUri,  false);         **//Getting the response**
xhr.send(null);

}

Upvotes: 0

Views: 86

Answers (1)

Andrey
Andrey

Reputation: 60105

You need to use a technique called cache busting. Something add this to your url:

xhr.open("GET", fullUri+'&rnd='+Math.random(), false);

This will make URL always unique and thus it will always be a cache miss.

Upvotes: 1

Related Questions