6

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?

1 Answer 1

6

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));
            }
        });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.