I am trying to pass request headers in an AJAX GET using jQuery. In the following block, "data" automatically passes the values in the querystring. Is there a way to pass that data in the request header instead ?
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: { signature: authHeader },
type: "GET",
success: function() { alert('Success!' + authHeader); }
});
The following didn't work either
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
beforeSend: { signature: authHeader },
async: false,
type: "GET",
success: function() { alert('Success!' + authHeader); }
});
This question is related to
jquery
ajax
client-side
$.ajax({_x000D_
url: URL,_x000D_
type: 'GET',_x000D_
dataType: 'json',_x000D_
headers: {_x000D_
'header1': 'value1',_x000D_
'header2': 'value2'_x000D_
},_x000D_
contentType: 'application/json; charset=utf-8',_x000D_
success: function (result) {_x000D_
// CallBack(result);_x000D_
},_x000D_
error: function (error) {_x000D_
_x000D_
}_x000D_
});
_x000D_
As of jQuery 1.5, there is a headers
hash you can pass in as follows:
$.ajax({
url: "/test",
headers: {"X-Test-Header": "test-value"}
});
From http://api.jquery.com/jQuery.ajax:
headers (added 1.5): A map 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.
Source: Stackoverflow.com