Skip to content

Instantly share code, notes, and snippets.

@keithics
Last active December 10, 2015 19:38
Show Gist options
  • Save keithics/4482228 to your computer and use it in GitHub Desktop.
Save keithics/4482228 to your computer and use it in GitHub Desktop.
Serialize by input - jQuery
/* @projectDescription jQuery Serialize Anything - Serialize anything (and not just forms!)
* @author Bramus! (Bram Van Damme)
* @version 1.0
* @website: http://www.bram.us/
* @license : BSD
* original file : http://www.bram.us/2008/10/27/jqueryserializeanything-serialize-anything-and-not-just-forms/
* modified by Keithics : keith@webninjamobile.com
* usage jQuery('.class_input').serializeAnything()
*/
(function($) {
$.fn.serializeAnything = function() {
var toReturn = [];
$.each(this, function() {
if (this.name && !this.disabled && (this.checked || /select|textarea/i.test(this.nodeName) || /text|hidden|password/i.test(this.type))) {
var val = $(this).val();
toReturn.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( val ) );
}
});
return toReturn.join("&").replace(/%20/g, "+");
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment