//application/x-www-form-urlencoded function QueryString(query) { var qs = {}; this.set = function(n, v) { qs[n.toLowerCase()] = v.toString(); return this; }; this.get = function(n) { return qs[n.toLowerCase()]; }; this.fromString = function(s) { var nvps = s.split('&'); for (i = 0; i < nvps.length; i++) { var nvp = nvps[i].split('='); if (!nvp[0]) continue; this.set(nvp[0], (nvp.length > 1) ? unescape(nvp[1].replace('+', ' ')) : ''); } return this; }; this.toObject = function() { return qs; }; this.toString = function(opt) { opt = opt || {}; var s = ''; for (q in qs) s += ( (opt.toCase == "upper" ? q.toUpperCase() : q) + '=' + escape(qs[q].replace(' ', '+')) + '&' ); return s.slice(0, -1); }; this.toUpperCaseString = function() { return this.toString({ toCase: "upper" }); }; this.applyTo = function(s, opt) { return s.split('?')[0] + '?' + this.toString(opt); }; this.applyUpperCaseTo = function(s) { return this.applyTo(s, { toCase: "upper" }); }; //Parse passed querystring parameter if present. if (!query) return; if (query.constructor === Object) for (q in query) this.set(query, query[q]); else if (query.constructor === String) this.fromString((query.indexOf('?') > -1) ? query.split('?')[1] : query); else throw new Error("Unsupported querystring type."); };