Skip to content

mslinn/jquery-deserialize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

jQuery deserialize

License

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.

Quick Review of jQuery's serialize Method

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);
  }
);

Using Deserialize

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);
  }
);

Why Not Add This to jQuery?

Seems like the jQuery committers probably don't want to do this.

Why Not Make This Into a jQuery Plugin?

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!

delighted

About

Populate an HTML form from a serialized string

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published