jQuery: How to stop AJAX function escaping JSON string used to POST data

前端 未结 5 1321
遇见更好的自我
遇见更好的自我 2020-12-11 02:07

I need to serialize all inputs from a form into a JSON string.
With the help of this post, I can successfully create a valid string as below:

{\"input01\         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 02:26

    This is the default behaviour of $.ajax(). You can change it by setting the processData option to false. See $.ajax() options.

    data  Object, String
    

    Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key i.e. {foo:["bar1", "bar2"]} becomes '&foo=bar1&foo=bar2'.

    and

    processData   Boolean Default: true
    

    By default, data passed in to the data option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded". If you want to send DOMDocuments, or other non-processed data, set this option to false.

提交回复
热议问题