I am using jQuery ajax to call my WCF service with an HTTP POST. The response is GZIP encoded, and this causes problems in my environment. (See this question). If the response i
This value is probably being overwritten later in the process.
Ref: http://api.jquery.com/jQuery.ajax/
headers (default: {}) description
Type: PlainObject
An object of additional header key/value pairs to send along with the request. This setting is set before the beforeSend function is called; therefore, any values in the headers setting can be overwritten from within the beforeSend function.
Try implementing beforeSend as seen in the demo code below and the header value(s) should get to the final request now (fingers crossed).
var ajaxParams = {
accepts: 'text/html',
async: true,
cache: false,
contentType: 'text/html',
url: 'http://www.google.com',
type: 'GET',
beforeSend: function (jqXHR) {
// set request headers here rather than in the ajax 'headers' object
jqXHR.setRequestHeader('Accept-Encoding', 'deflate');
},
success: function (data, textStatus, jqXHR) {
console.log('Yay!');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('Oh no!');
},
complete: function (jqXHR, textStatus) {
console.log(textStatus);
console.log(jqXHR.status);
console.log(jqXHR.responseText);
}
};
$.ajax(ajaxParams);