O'Reilly logo

PHP jQuery Cookbook by Vijay Joshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Preventing browser from caching AJAX requests

In case of GET requests, browsers cache these requests and when the request is invoked again they do not send the request to the server and instead serve it from the cache.

This recipe will explain how to force browsers to send the request to a server instead of serving it from the cache.

How to do it...

  1. While sending an AJAX request use the cache option to force no caching by the browser. Setting the cache option to false does not let the browser cache any AJAX requests and the data is loaded from the server each time the request is made.
    $.ajax({
    url : 'someurl.php',
    cache: false,
    success: function(data)
    {
    //do something with received data
    }
    });
    

How it works...

On an AJAX request, the browser checks ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required