mrrsb
mrrsb

Reputation: 671

How to get parameter in jquery ajax?

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.

Upvotes: 0

Views: 308

Answers (2)

deadrunk
deadrunk

Reputation: 14135

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

Upvotes: 2

frumbert
frumbert

Reputation: 2427

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

Upvotes: 0

Related Questions