-1

I have two htmls namely index.html and grid.html. I need to refresh grid contents according to the dropdown values being selected in the index.html file.

In my index.html page I've this code,

$(document).ready(function() {
    $('#orderTypeOptions').change(function() {
        var oType = $('#oTypeOptions').val();
        $('#ordersGrid').load('grid2.html?oType='+oType);
    });
});

My question is, how can I retrieve the url parameter "oType" value in the grid page?. Can anyone help?

nathanjosiah
  • 4,441
  • 4
  • 35
  • 47
David R
  • 14,711
  • 7
  • 54
  • 72
  • How does the rendered HTML looks like? what is the response from the server? – gdoron Mar 27 '12 at 14:33
  • 1
    This would be no different to how you would retreive the value if you simply typed the URL in your browser bar. I don't see this as a `javascript` or `jquery` question. – Curtis Mar 27 '12 at 14:35
  • I'm getting the grid with the normal data. (It is not rendering according to the filter type whichever we tend to change in the dropdown). Moreover I'm not able to retrieve the "oType" parameter value in the grid.html page. – David R Mar 27 '12 at 14:35
  • You may benefit by [loading page fragments](http://api.jquery.com/load/#loading-page-fragments) instead of using a query string. – Blazemonger Mar 27 '12 at 14:35
  • @Curt When we I use any custom javascript URL extractor function, I'm able to get only the absolute url (like http://localhost:8080/webservice/grid.html), it is not returning any url parameters. – David R Mar 27 '12 at 14:40

3 Answers3

2

It's in the window.location.search variable as a string. You need to parse it to name value pairs and find the variable you are interested in.

Peter Aron Zentai
  • 11,482
  • 5
  • 41
  • 71
0

What about window.location.search?

Ash Clarke
  • 4,807
  • 1
  • 37
  • 48
0

Use a JavaScript function to retrive the URL parameter.

Example taken taken from: Get escaped URL parameter

function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}

Example usage in the grid.html file:

var oType = getURLParameter("oType");

Community
  • 1
  • 1
Telmo Marques
  • 5,066
  • 1
  • 24
  • 34
  • When I use any custom javascript URL extractor function, I'm able to get only the absolute url (like localhost:8080/webservice/grid.html), it is not returning any url parameters – David R Mar 27 '12 at 14:47
  • @DavidR you're saying that `alert(location.search);` only displays the URL without the querystring? – Telmo Marques Mar 27 '12 at 14:54