0

Need help..how can I get the parameter pass by the ajax..

url: test.htm?a=1&b=2&c=3

I want to get the value of b.

mrrsb
  • 591
  • 3
  • 9
  • 26

2 Answers2

2
function getQueryString(queryString) {
  var result = {},
      re = /([^&=]+)=([^&]*)/g, m;

  while (m = re.exec(queryString)) {
    result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
  }

  return result;
}

var query = "test.htm?a=1&b=2&c=3"
var myParam = getQueryString(query)["b"];
alert(myParam);
deadrunk
  • 12,675
  • 4
  • 27
  • 29
0

the "dirty" way is to location.search.split("&b=")[1].split("&")[0]; but that's not reusable and I'll get flamed about it for sure...

the better way has been answered here before: https://stackoverflow.com/a/2091331/1238884

Community
  • 1
  • 1
frumbert
  • 2,014
  • 4
  • 25
  • 55