deserialize
is the counterpart to jQuery's serialize method.
I did not write the deserialize
method, it evolved on StackOverflow.
I just renamed it to deserialize
.
The serialize()
method creates a text string in standard URL-encoded notation.
Typically the serialize()
method is used to serialize an entire <form>
.
Here is an example of serializing form data into a string:
var serializedFormData = $("#myForm").serialize();
In the following example, jQuery sends a POST to url
, containing data serialized from
the form with id myForm
.
The server's response (assumed to be HTML for the sake of this example) to the POST is used to inflate the <div>
with id myDiv
:
var url = "http://blah.com/whatever";
$.post(
url,
$("#myForm").serialize(),
function(data) {
$("#myDiv").html(data);
},
).fail(function(jqXHR, textStatus, errorThrown) {
alert(textStatus + ": " + errorThrown);
}
);
Use the deserialize
method provided by deserialize.js
to populate a form from a serialized string.
This code example shows how an Ajax call to url
that returns data with Content-Type: application/x-www-form-urlencoded
populates the form fields in the form with id myForm
:
var url = "http://blah.com/whatever";
$.get(url, function(data) {
$("#myForm").deserialize(data)
},
).fail(function(jqXHR, textStatus, errorThrown) {
alert(textStatus + ": " + errorThrown);
}
);
Seems like the jQuery committers probably don't want to do this.
I don't have the time or the energy. If someone else forked this repo and moved forward with such a plugin, however, I would be delighted!