Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between jQuery serialize() method vs JSON.stringify()?

Maybe I'm getting this all mixed up, but reading about jQuery's serialize() method has gotten be confused. I normally use JSON.stringify() when I need to serialize an object for an AJAX request. Are these two methods similar in any way?

like image 747
biddano Avatar asked Mar 30 '14 09:03

biddano


People also ask

What is difference between serialize and Stringify?

stringify() ignores functions/methods when serializing. JSON also can't encode circular references. Most other serialization formats have this limitation as well but since JSON looks like javascript syntax some people assume it can do what javascript object literals can. It can't.

What is the use of serialize () method in jQuery?

jQuery serialize() Method The serialize() method creates a URL encoded text string by serializing form values. You can select one or more form elements (like input and/or text area), or the form element itself. The serialized values can be used in the URL query string when making an AJAX request.

What is the difference between JSON Stringify and JSON parse?

JSON. stringify() takes a JavaScript object and then transforms it into a JSON string. JSON. parse() takes a JSON string and then transforms it into a JavaScript object.

What is the purpose of JSON Stringify?

JSON.stringify() The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.


1 Answers

JSON.stringify produces application/json data from a JavaScript object or array.

jQuery.serialize produces application/x-www-form-urlencoded data (the standard encoding for HTML form submissions) from a jQuery object containing an HTML Form Element or a set of form controls.

like image 191
Quentin Avatar answered Oct 10 '22 10:10

Quentin