Skip to content

Instantly share code, notes, and snippets.

@darbicus
Created July 17, 2014 18:07
Show Gist options
  • Save darbicus/3c2a1a83851cbf301f60 to your computer and use it in GitHub Desktop.
Save darbicus/3c2a1a83851cbf301f60 to your computer and use it in GitHub Desktop.
serialize javascript objects for get http requests that submit data
function cerealize(object) {
return Object.getOwnPropertyNames(object)
.filter(function (e) {
return typeof object[e] !== 'function' && object[e].toString
})
.map(function (n) {
return encodeURIComponent(n) + "=" + encodeURIComponent(object[n]);
})
.join("&")
}
cerealize(Math);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment