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'}