var obj = {
'key': 'value',
'cheese':'bacon',
'&':'>'
};
var params = $.param(obj)
console.log(params); // key=value&cheese=bacon&%26=%3E
how do I turn params
back into an object? (exactly what it was before)
var obj = {
'key': 'value',
'cheese':'bacon',
'&':'>'
};
var params = $.param(obj)
console.log(params); // key=value&cheese=bacon&%26=%3E
how do I turn params
back into an object? (exactly what it was before)
You could use something like this. I'm not aware of a jQuery built-in for this.
function getUrlVars() {
if (!window.location.search) {
return({}); // return empty object
}
var parms = {};
var temp;
var items = window.location.search.slice(1).split("&"); // remove leading ? and split
for (var i = 0; i < items.length; i++) {
temp = items[i].split("=");
if (temp[0]) {
if (temp.length < 2) {
temp.push("");
}
parms[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
}
}
return(parms);
}
jQuery BBQ has a deparam function: https://github.com/cowboy/jquery-bbq/blob/master/jquery.ba-bbq.js line 466