Skip to content

Instantly share code, notes, and snippets.

@say2joe
Created November 30, 2012 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save say2joe/4172829 to your computer and use it in GitHub Desktop.
Save say2joe/4172829 to your computer and use it in GitHub Desktop.
jQuery extension for form GET requests requiring comma-separated values.
/**
* 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