我正在尝试使用 jQuery 在 AJAX GET 中传递请求 header 。在接下来的 block 中,“数据”自动传递查询字符串中的值。有没有一种方法可以改为在请求 header 中传递该数据?
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: { signature: authHeader },
type: "GET",
success: function() { alert('Success!' + authHeader); }
});
下面的也不行
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
beforeSend: { signature: authHeader },
async: false,
type: "GET",
success: function() { alert('Success!' + authHeader); }
});
最佳答案
从 jQuery 1.5 开始,有一个 headers
哈希,您可以按如下方式传入:
$.ajax({
url: "/test",
headers: {"X-Test-Header": "test-value"}
});
来自 http://api.jquery.com/jQuery.ajax :
headers (added 1.5): A map of additional header key/value pairs to send along with the request. This setting is set before the beforeSend function is called; therefore, any values in the headers setting can be overwritten from within the beforeSend function.
关于jquery - 在 jQuery AJAX GET 调用中传递请求 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3258645/