这是一个有点可笑的问题,但我如何在 jquery 中设置多个自定义 http header ?
这个答案:https://stackoverflow.com/a/14655768/2554598 解释为一个标题执行此操作,例如:
// Request with custom header
$.ajax({
url: 'foo/bar',
headers: { 'x-my-custom-header': 'some value' }
});
这行得通。然而
// Request with custom header
$.ajax({
url: 'foo/bar',
headers: [{ 'my-first-header': 'blub'}, { 'my-second-header': 'peng'}]
});
这会创建一个奇怪的空头字段,其中包含一个 json 数组。
最佳答案
Property headers 是一个对象,所以只需尝试:
headers: { 'my-first-header': 'blub', 'my-second-header': 'peng'}
关于javascript - 使用 jquery ajax 设置多个请求 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35536459/