aseipel
aseipel

Reputation: 728

How to show content based on the URL?

unfortunately, I have no idea how you call this and had no success finding an answer to my question. Basically, I have built a JS application where the user enters a name and the application will then fetch and process data from an API based on that name.

What I want to do now is that if someone goes to http://www.mywebsite.com/NAME, the data will be fetched/processed for NAME. I know how it works with PHP (xxx.php?name=NAME) but if possible I don't want to use PHP here.

Thank you!

Upvotes: 1

Views: 125

Answers (2)

Chirag Bhatia - chirag64
Chirag Bhatia - chirag64

Reputation: 4516

The easiest way to do this is by using URL Rewrite. This does not require any coding in JS or server-side language. This can be done on most server softwares but the method is different depending on what server (IIS, Apache, nginx, etc.) you're using.

Here's an article about URL Rewriting to help you get started.

Upvotes: 1

Matt
Matt

Reputation: 457

For JavaScript you could use the location object.

var url =  window.location.href;

var param = url.replace('http://www.mywebsite.com/', '');

Look at Backbone routers for a more organised way of handling params in JavaScript.

http://backbonejs.org/#Router

Upvotes: 0

Related Questions