14

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 1

23

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
They take different input and give different output, so you can't use the interchangeably.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.