Posting JSON with JQuery

后端 未结 2 1180
走了就别回头了
走了就别回头了 2021-01-01 05:10

Trying to get JQuery to post JSON to a server:

$.ajax({  
  url: \"/path/to/url\",  
  type: \"POST\",  
  dataType: \"json\",  
  contentType: \"json\",  
          


        
相关标签:
2条回答
  • 2021-01-01 05:49

    You could use json2.js:

    data: JSON.stringify({"foo": "bar"})
    
    0 讨论(0)
  • 2021-01-01 05:53

    Datatype is for returned data. Contenttype is not applicable, see here

    It can only send strings, I use JSON.stringify on my created javascript objects, in your case you could just manually code the string.

    You will also need to access the string on server side, for that if you are using java I can recommened google's gson

    0 讨论(0)
提交回复
热议问题