I have a problem with the ajax
GET function. I can not send the header from my GET function.
This is my ajax code:
<script type="text/javascript">
function login() {
$.ajax({
url: 'http://localhost:8085/api/test',
beforeSend: function (xhr) {
xhr.setRequestHeader('token', 'test');
},
dataType: 'JSONP',
jsonpCallback: 'callbackFnc',
type: 'GET',
async: false,
crossDomain: true,
success: function () { },
failure: function () { },
});
}
</script>
Does anyone know where is the problem?
2
Answers
You just need to add
header
property to the objectYou can set the headers: