Jump to content

How get specific parameter from URL


aneeb

Recommended Posts

Hey everyone! i want to get some specific parameters from URL. If the url contains id then do this and if the url contains userno then do this and if it didn't contain anything do this. I want to put it in If else statement. the url is like this If it didn't contain anythinghttp://localhost:8080/web/promotions.html If it contains idhttp://localhost:8080/web/promotions.html?id=Food If it contain usernohttp://localhost:8080/web/promotions.html?userno=12 How can i do this? Please help me i am new to this..

Link to comment
Share on other sites

ajax call and the $_GET array. See:http://www.w3schools.com/php/php_ajax_intro.asp

Link to comment
Share on other sites

I am doing it like this

if((location.search=="") ? "" : "userno"){  var get = '';  var userno = getUrlVars()["userno"];  get = 'getpromotions.php?userno='+userno;}else if((location.search=="") ? "" : "id"){   var get = '';  var id = getUrlVars()["id"];  get = 'getpromotions.php?id='+id;}else{  var get = '';  get = 'getpromotions.php';  }

In this only If and Else are working, else if statement is not working..

Link to comment
Share on other sites

It's "working", but it's never going to go into that block because the second if statement checks the same condition as the first if statement. Both of them will only execute if location.search is empty, and if it's empty then only the first block will get executed.

Link to comment
Share on other sites

Save the results and check each one.

var urlVars = getUrlVars();var urlId = '';var urlUserno = '';if (urlVars['id'] != undefined) urlId = urlVars['id'];if (urlVars['userno'] != undefined) urlUserno = urlVars['userno'];

Now you can check the values of urlId and urlUserno to figure out what you want to do.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...