0

So I'm trying to make a website where you put in a username and it will give you data about that username using an API. Right now I have it set up so you have to type the username in every time you're on the website, but I was wondering if it's possible to put the username in the link and still be able to retrieve it to put it into an API and use the API's response in the website?

For example, would it be possible to have something like http://website.com/?username=XXXXXXXXXand to be able to get the part after ?username= and to save it to a string or something to put into the API using JavaScript or jQuery? Any help would be appreciated :)

Connor S
  • 25
  • 7
  • 3
    Possible duplicate of [How to retrieve GET parameters from javascript?](http://stackoverflow.com/questions/5448545/how-to-retrieve-get-parameters-from-javascript) – Michael Longhurst Feb 28 '17 at 01:40

1 Answers1

0

why don't you saving username in cookie/storage/session after user input?your ways is complex and unreliable.or may be you could use the rest url format like this: http://{username}.example.com/api or http://www.example.com/{user}/api then your backend always retrieves username from this path and you needn't add parameters manually.

holi-java
  • 29,655
  • 7
  • 72
  • 83
  • Mainly because I want it to be possible to send the link to another person, and have it so when they click on it all the information for that user is there without needing for them to put in their username. If you know of a better way to do that I'll take any advice :) – Connor S Feb 28 '17 at 01:55
  • use the rest url can solve your problem.and then in your server config an urlrewrite to resolve the parameter.like this: browser: `http://www.example.com/{user}/api` backend urlrewrite: `http://www.example.com/api?username={user}` – holi-java Feb 28 '17 at 01:57
  • saving parameters in path nor query having one primary benefit,when user jump to another page,the relative pages url can also retrieves this parameters. – holi-java Feb 28 '17 at 02:02