Do you know a fast and simple way to encode a Javascript Object into a string that I can pass via a GET Request?
string
GET
No jQuery, no other frameworks - just plain Javascript :)
jQuery
like this?
serialize = function(obj) { var str = []; for (var p in obj) if (obj.hasOwnProperty(p)) { str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); } return str.join("&"); } console.log(serialize({ foo: "hi there", bar: "100%" })); // foo=hi%20there&bar=100%25
2.1m questions
2.1m answers
60 comments
57.0k users