Last active
December 10, 2015 19:38
-
-
Save keithics/4482228 to your computer and use it in GitHub Desktop.
Serialize by input - jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @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 : [email protected] | |
* 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