Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Ajax caching

Tags:

jquery

caching

I make a few Ajax calls to get files via jQuery like so:

$.ajax({
        url: "/resx.mvc",
        data: {
            virtualPath: options.virtualPath,
            keys: options.keys,
            global: options.global
        },
        cache: true,
        success: function (values) {
            $.extend(assignTo, values);
        },
        dataType: "JSON",
        traditional: true
    });

When I look at the request in Fiddler, I see that these two headers are being sent, and making my ASP.NET send back an expires header on its response with -1:

Pragma: no-cache
Cache-Control: no-cache

How do I tell jQuery not to issue no-cache?

like image 732
PostgresQLNewb Avatar asked Mar 16 '11 14:03

PostgresQLNewb


1 Answers

beforeSend takes an ajax object (XmlHttpRequest object) which you can use to manipulate the request header. Below is an example of setting a header in your request using the ajax object returned in the callback:

$.ajax({
            type:"POST",
            beforeSend: function (request)
            {
                request.setRequestHeader("Authority", authorizationToken);
            },
            url: "entities",
            data: "json=" + escape(JSON.stringify(createRequestObject)),
            processData: false,
            success: function(msg) {
                $("#results").append("The result =" + StringifyPretty(msg));
            }
        });
like image 94
Pranay Rana Avatar answered Oct 30 '22 20:10

Pranay Rana