PostgresQLNewb
PostgresQLNewb

Reputation: 339

jQuery Ajax 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?

Upvotes: 6

Views: 11213

Answers (1)

Pranay Rana
Pranay Rana

Reputation: 176896

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));
            }
        });

Upvotes: 6

Related Questions