У меня проблема с функцией ajax
GET. Я не могу отправить заголовок из моей функции GET. Это мой код AJAX:
<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>
Кто-нибудь знает, где проблема?
Всего 2 ответа
Вам просто нужно добавить свойство header
к объекту
$.ajax({
url: 'http://localhost:8085/api/test',
headers: {'token': 'test'}
});
Вы можете установить заголовки:
<script type="text/javascript">
function login() {
$.ajax({
url: 'http://localhost:8085/api/test',
headers: {'token': 'test'}
dataType: 'JSONP',
jsonpCallback: 'callbackFnc',
type: 'GET',
crossDomain: true,
success: function () { },
failure: function () { },
});
}
</script>