dongliao1949 2015-05-07 13:09
浏览 28

jQuery&Go:如何设置JSON标头

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) {
...
  • 写回答

3条回答 默认 最新

  • dongwen7380 2015-05-07 13:12
    关注

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

报告相同问题?