Reputation: 181
Ive done my fair share of Googling and searching Stack Overflow but for some reason cannot completely grasp the concept of Serialize / Unserialize. I understand the definition of turning an object into a text string that can be queried through a URL but what exactly would that be used for? Any examples using an HTML form / Jquery would be great for me because I figure if I were to use it thats what I would start with. Any help in understanding this is appreciated!
Upvotes: 0
Views: 148
Reputation: 21174
If you are using AJAX, you can make the URL something like 'http://www.example.com' + $('form').serialize(). This is almost identical to the URL you would see when submitting a form with a 'GET' method.
In effect, it is getting all the form values, and putting them in the URL using something like serializedString = '?' + myArray.join('&')
to make it work like a GET url with parameters.
Upvotes: 0
Reputation: 29925
AJAX requests is a specific use for this!
$('form#myForm').serialize()
creates a nicely formatted serialised string to send in a jQuery.AJAX request (in the data
bit). Otherwise you're going to have to do data: 'variable='+$('#textarea').val()+'&another='+$('#input')+'etc...'
.
Upvotes: 1
Reputation: 360682
Think of serialization as the programmatic equivalent of MIME-encoding for email, or UUencoding for newsgroup posting. It's there to convert some internal binary format into an easily transmissible format through systems which may otherwise mangle the binary representation.
Upvotes: 2