我查看了各种帖子,现在使用一个函数从 url 检索值,但无法摆脱 %20 个字符。发送的数据是 json,这里是在 url 中发送它的代码:
'<a href="' + url +"?id="+ json_data[i].product_id +
...
"&description="+ json_data[i].description + '"> //includes white spaces
在另一页上我有:
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
var selectedData=getUrlVars();
document.write(selectedData.description);