Przekazać nagłówki żądań w wywołaniu jQuery AJAX GET
Próbuję przekazać nagłówki żądań w AJAX GET używając jQuery. W poniższym bloku "data" automatycznie przekazuje wartości w zapytaniu. Czy istnieje sposób na przekazanie tych danych w nagłówku żądania ?
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: { signature: authHeader },
type: "GET",
success: function() { alert('Success!' + authHeader); }
});
Poniższe też nie zadziałały
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
beforeSend: { signature: authHeader },
async: false,
type: "GET",
success: function() { alert('Success!' + authHeader); }
});
199
3 answers
Użycie beforeSend
:
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: { signature: authHeader },
type: "GET",
beforeSend: function(xhr){xhr.setRequestHeader('X-Test-Header', 'test-value');},
success: function() { alert('Success!' + authHeader); }
});
Http://api.jquery.com/jQuery.ajax/
Http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method
232
Author: Adam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-18 20:52:58
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-18 20:52:58
Od jQuery 1.5, istnieje headers
hash, który możesz przekazać w następujący sposób:
$.ajax({
url: "/test",
headers: {"X-Test-Header": "test-value"}
});
Z http://api.jquery.com/jQuery.ajax :
Nagłówki (dodano 1.5): Mapa dodatkowych par nagłówek klucz / wartość do wysłania wraz z żądaniem. To ustawienie jest ustawiane przed wywołaniem funkcji beforeSend; dlatego wszelkie wartości w Ustawieniach nagłówków mogą być nadpisane z poziomu funkcji beforeSend.
333
Author: Lukas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-11 15:00:07
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-11 15:00:07
$.ajax({
url: URL,
type: 'GET',
dataType: 'json',
headers: {
'header1': 'value1',
'header2': 'value2'
},
contentType: 'application/json; charset=utf-8',
success: function (result) {
// CallBack(result);
},
error: function (error) {
}
});
24
Author: enthusiast,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-07-05 07:19:21
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-07-05 07:19:21