Showing posts with label parameter reading from the url. Show all posts
Showing posts with label parameter reading from the url. Show all posts

Friday, 18 January 2013

How to read parameters from URL


Suppose your URL is -- > http://localhost:3000/decorations/expense?decoration=32

Step 1: Add a function inside your js file


function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}


Step 2: Retrieve the data in a variable by using below line


var deco = getUrlVars()["decoration"];