在Javascript中将查询字符串传递给WebMethod
可能重复:在Javascript中将查询字符串传递给WebMethod,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,可能重复: 从中获取“test1”的最佳方法是什么 ,并通过PageMethod将其传递给webmethod。我认为一种方法是从window.location.pathname中提取,剪切字符串并像传递参数一样传递它 试试看 string username = Request.QueryString["username"]; 在PageMethod中,您可以 string username = HttpContext.Current.Request.QueryString["usernam
从中获取“test1”的最佳方法是什么 ,并通过PageMethod将其传递给webmethod。我认为一种方法是从window.location.pathname中提取,剪切字符串并像传递参数一样传递它 试试看
string username = Request.QueryString["username"];
在PageMethod中,您可以
string username = HttpContext.Current.Request.QueryString["username"];
可能您只能使用javascript,如:
var search = function(){
var s = window.location.search.substr(1),
p = s.split(/\&/),
l = p.length,
kv, r = {};
if(l === 0){return false;}
while(l--){
kv = p[l].split(/\=/);
r[kv[0]] = kv[1] || true;
}
return r;
}();
然后在你的代码
搜索中使用。用户名看看这里:是的,我尝试了第二个,但是我得到了空值。