admin管理员组文章数量:1344067
This is a bit of a ridiculous question, but how do I set multiple custom http headers in jquery?
This answer: explains to do it for one header like:
// Request with custom header
$.ajax({
url: 'foo/bar',
headers: { 'x-my-custom-header': 'some value' }
});
This works. However
// Request with custom header
$.ajax({
url: 'foo/bar',
headers: [{ 'my-first-header': 'blub'}, { 'my-second-header': 'peng'}]
});
This creates a strange empty header field, containing a json array.
This is a bit of a ridiculous question, but how do I set multiple custom http headers in jquery?
This answer: https://stackoverflow./a/14655768/2554598 explains to do it for one header like:
// Request with custom header
$.ajax({
url: 'foo/bar',
headers: { 'x-my-custom-header': 'some value' }
});
This works. However
// Request with custom header
$.ajax({
url: 'foo/bar',
headers: [{ 'my-first-header': 'blub'}, { 'my-second-header': 'peng'}]
});
This creates a strange empty header field, containing a json array.
Share Improve this question edited May 23, 2017 at 12:00 CommunityBot 11 silver badge asked Feb 21, 2016 at 13:01 icehawkicehawk 1,2353 gold badges13 silver badges22 bronze badges 1-
2
try
headers: { 'my-first-header': 'blub', 'my-second-header': 'peng'}
– Jaromanda X Commented Feb 21, 2016 at 13:02
1 Answer
Reset to default 9Property headers is an object so just try:
headers: { 'my-first-header': 'blub', 'my-second-header': 'peng'}
本文标签: javascriptsetting multiple request headers with jquery ajaxStack Overflow
版权声明:本文标题:javascript - setting multiple request headers with jquery ajax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743744722a2531544.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论