3

This is a bit of a ridiculous question, but how do I set multiple custom http headers in jquery?

This answer: https://stackoverflow.com/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.

1
  • 2
    try headers: { 'my-first-header': 'blub', 'my-second-header': 'peng'} Commented Feb 21, 2016 at 13:02

1 Answer 1

9

Property headers is an object so just try:

headers: { 'my-first-header': 'blub', 'my-second-header': 'peng'}
Sign up to request clarification or add additional context in comments.

1 Comment

I should have spotted this myself. Thanks very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.