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) { ... 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) { ... 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) { ... 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) { ...