Created
November 30, 2012 00:13
-
-
Save say2joe/4172829 to your computer and use it in GitHub Desktop.
jQuery extension for form GET requests requiring comma-separated values.
This file contains 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
/** | |
* Extend jQuery with additional functionality to be used throughout app. | |
*/ | |
$.fn.extend({ | |
/** formData: | |
* Most form submissions will require special formatting different from | |
* a normal get request (a=val1,val2&b=val3 vs. a=val1&a=val2&b=val3). | |
* Sample use: $.getJSON(url,$("myFormElement").formData(),callback);. | |
* @return {String} Serialized form data appropriate for GET requests. | |
* @author Joe Johnson | |
*/ | |
formData: function(){ | |
var data = {}; | |
$.each(this.serializeArray(),function(i,o){ | |
if (data[o.name]) data[o.name] += ','+o.value; | |
else data[o.name] = o.value; | |
}); | |
return $.param(data); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment