How to set headers to $.get() or $.post() function
You can define ajaxsetup before your request $ .get () to include the authorization in the header
$.ajaxSetup({
headers:{
'Authorization': "auth username and password"
}
});
$.get(urlAPI + "/api/account/get", function (data) {
alert(data);
}, 'json');
$.ajax({
url: 'foo/bar',
headers: { 'x-my-custom-header': 'some value' }
});
based on jquery page $.get() document from version 1.12 there is a settings option to pass the base settings to the method.
jQuery.get( [settings ] )
or
$.get( [settings] )
settings
is a plain object so you can use it like
{
url: 'http://requesturl.io',
data: {},
headers: { 'your-custom-header': 'custom-header-value' }
}