Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中将查询字符串传递给WebMethod_Javascript_Jquery_Asp.net - Fatal编程技术网

在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;
}();

然后在你的代码
搜索中使用。用户名

看看这里:是的,我尝试了第二个,但是我得到了空值。