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?
1 Answer
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.
2 Comments
biddano
Alright and would they be used for different scenarios or can I use them interchangeably? For example, is
JSON.stringify just for objects/arrays and jQuery.serialize just for submitting forms?Quentin
They take different input and give different output, so you can't use the interchangeably.