0

有人可以告诉我如何将地址栏变量添加到我的 javascript 中吗?

The website address reads: www.example.com/index.php?user=74

需要包含'user = 74'的javascript是:

xmlhttp.open("GET","../profile/" + pageName + ".php",true);
4

1 回答 1

0
function get_query(){
  var url = location.href;
  var qs = url.substring(url.indexOf('?') + 1).split('&');
  for(var i = 0, result = {}; i < qs.length; i++){
    qs[i] = qs[i].split('=');
    result[qs[i][0]] = decodeURIComponent(qs[i][1]);
  }
  return result;
}

xmlhttp.open("GET","../profile/" + pageName + ".php?user=" + get_query()['user'],true);
于 2013-08-23T21:34:20.623 回答