开发者

Pass Query string to WebMethod in Javascript [duplicate]

开发者 https://www.devze.com 2023-03-17 17:30 出处:网络
This question already has answers here: Closed 11 years ago. 开发者_如何学编程 Possible Duplicate:
This question already has answers here: Closed 11 years ago. 开发者_如何学编程

Possible Duplicate:

Get query string values in JavaScript

What is the best way to get "test1" from

http://localhost:3311/blabl/allprofiles.aspx?username=test1

, and through PageMethod pass it to webmethod. I think one way is to take from window.location.pathname, cut the string and pass it like a parameter.


May be you can use only javascript like:

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

Then use in your code search.username


Try

string username = Request.QueryString["username"];

In a PageMethod, you can do

string username = HttpContext.Current.Request.QueryString["username"];
0

精彩评论

暂无评论...
验证码 换一张
取 消