2

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.

Community
  • 1
  • 1
icehawk
  • 1,145
  • 3
  • 12
  • 21

1 Answers1

9

Property headers is an object so just try:

headers: { 'my-first-header': 'blub', 'my-second-header': 'peng'}
Dario
  • 6,152
  • 9
  • 39
  • 50