0

How do you set a json header in query. I need it to be a string on the server?:

... $.ajax({ url: '', headers: { "listkey":{"key1":"val1", "key2": "val2", "key3":"val3"} }, dataType: 'json', cache: false, success: function(data) { ... 
1

3 Answers 3

1

I believe it's a simple as adding:

contentType: "application/json" 

as an object property. See the contentType property in the docs.

Full Example:

... $.ajax({ url: '', contentType: 'application/json', headers: { "listkey":{"key1":"val1", "key2": "val2", "key3":"val3"} }, dataType: 'json', cache: false, success: function(data) { ... 
Sign up to request clarification or add additional context in comments.

Comments

1

you can use the contentType property to set the content-type header, i.e. what you are sending to the server.

And you can use the accept property to tell the server what you would like back.

$.ajax({ contentType: 'application/json', accept: 'application/json', url: '', headers: { "listkey":{"key1":"val1", "key2": "val2", "key3":"val3"} }, dataType: 'json', cache: false, success: function(data) { ... 

Comments

0

This worked:

$.ajax({ contentType: 'application/json', accept: 'application/json', url: '', headers: { "listkey": '{"key1":"val1", "key2": "val2", "key3":"val3"}' }, dataType: 'json', cache: false, success: function(data) { ... 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.