jQuery - How to PUT JSON via Ajax?

前端 未结 3 974
感动是毒
感动是毒 2020-12-01 07:25

I am trying to put some JSON formatted data via Ajax with jQuery to a server. My code looks like this:

$.ajax({
    type: \"PUT\",
    url: myURL,
    conten         


        
3条回答
  •  不知归路
    2020-12-01 07:42

    I think the data needs to be a String. Objects are converted to query strings which is what you are seeing here.

    You can use the JSON.stringify(obj) method to convert your Object to a String. The code for the JSON object is available from: https://github.com/douglascrockford/JSON-js/blob/master/json2.js.

    Alternately, just pass the code you are using to create the object as a literal String, but I imagine this is just an example and you'll want to encode some object you've already created.

提交回复
热议问题