Reputation: 1002
I having url in query string like http://www.domain.com:3000/allot_room?floor=6&hostel=1&student=1.In that, how to get student parameter value using jquery.
I have used this code
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
It shows like floor=6,hostel=1,student=1.In that how to get student parameter value.And I tried different codes.
Upvotes: 0
Views: 168
Reputation: 3170
use var url = window.location.search
and from MDN -
Get the value of a single window.location.search key:
function loadPageVar (sVar) {
return decodeURI(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURI(sVar).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
}
alert(loadPageVar("floor"));
alert(loadPageVar("student"));
Upvotes: 2