Phoenix Phoenix - 1 year ago 73
Ajax Question

Need help to fetch data from a URL parameter using Ajax or Java Script

I need to get the data in a URL parameter and assign it in a LABEL in another page...

The URL is : http://localhost:60391/pages/reservations.html?3

I need to fetch that 3 and assign it to Label in my webpage with ID #TestLabel.

Can anyone help me with a Java Script/ Ajax to make this possible?

Answer Source

This should do it:

var parts = document.location.href.split("?");
if (parts.length === 2) {
    document.getElementById("TestLabel").textContent = parts[1];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download