2

I have in the below parameters for all ajax calls in the <head> of my document. (I need this for an iOS ajax bug at https://stackoverflow.com/a/12856562/627473

$.ajaxSetup ({
            cache: false,
            headers: { "cache-control": "no-cache" }
        });

I have a service that I am communicating with the specifically denies the cache-control header in any way.

So I tried the below BEFORE making ajax request.

$.ajaxSetup ({
cache: true,
headers: { 'Invoke-Control': 'EMVX' }
});

The above request still includes "cache-control": "no-cache" as a header. A requirement of the service I am making a request prohibits the cache-control header from being in the request (even if it is blank or has a cache value.

My request also includes the invoke-control (which I want); but I do NOT want cache-control to show up at all.

I even tried specifying headers in the $.post request by itself and it still merges the headers from $.ajaxSetup.

I am using jQuery v1.11.1. Is there a workaround?

Sagar V
  • 12,158
  • 7
  • 41
  • 68
Chris Muench
  • 17,444
  • 70
  • 209
  • 362

1 Answers1

0

There is no way you can do it.

According to the jQuery Documentation of jQuery.ajaxSetup,

The settings specified here will affect all calls to $.ajax or Ajax-based derivatives such as $.get(). This can cause undesirable behaviour since other callers (for example, plugins) may be expecting the normal default settings. For that reason we strongly recommend against using this API. Instead, set the options explicitly in the call or define a simple plugin to do so.

It clearly indicates that it will append the header to all calls.

To prevent this,

You can do the following

Instead of using $.ajaxSetup, try to use

$.ajax({
   beforeSend: function(){
     jqXHR.setRequestHeader("cache-control","no-cache");
}

To specific requests you want

Sagar V
  • 12,158
  • 7
  • 41
  • 68