To set custom headers in an AJAX request using jQuery, you can use the headers
property of the $.ajax()
function. Here is an example:
$.ajax({
url: 'your-url',
type: 'GET',
headers: {
'Authorization': 'Bearer your-token',
'CustomHeader': 'value'
},
success: function(response) {
// Handle success response
},
error: function(xhr, status, error) {
// Handle error response
}
});
In this example, the headers
property is an object containing key-value pairs representing the custom headers to be set in the request. The Authorization
header is set to a bearer token, and the CustomHeader
is set to a custom value.
Note that you need to replace 'your-url'
with your actual URL, and 'your-token'
with your actual token value.