Get Parameters from internal page
Hi I have two pages which are generated dynamically and one of the page has parameters as <li><a href="?cid=1234&sid=test#display2" to navigate to display2 page..
but when i try to get the parameters cid and sid i get null value but if i put rel=external I get the values of it bur the page refreshes which i don't need. please let me know how to write code and implement it ...
here is the code
- <!DOCTYPE html>
- <html>
-
- <head>
- <title>Test</title>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css"
- />
- <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
- <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
- <script src="js/jqm.page.params.js" type="text/javascript"></script>
- </head>
-
- <body>
- <!-- Glossary -->
- <div data-role="page" id="glossary">
- <div data-role="header">
- <h3>Glossary</h3>
- </div>
- <div data-role="content">
- <ul data-role='listview' data-inset='true' id='resultsList'>
- <!-- keep empty for dynamically added items -->
- </ul>
- </div>
- </div>
- <!-- display -->
- <div data-role="page" id="display">
- <div data-role="header">
- <h3>Name Goes Here</h3>
- <a data-role="button" data-rel="back" data-icon="back">Back</a>
- </div>
- <div data-role="content">
- <ul data-role='listview' data-inset='true' id='categoryList'>
- <div id="definition">Definition goes here</div>
- </div>
- </div>
- <div data-role="page" id="display2">
- <div data-role="header">
-
- <a data-role="button" data-rel="back" data-icon="back">Back</a>
- </div>
- <div data-role="content">
- <ul data-role='listview' data-inset='true' id='categoryList2'>
-
- </div>
- </div>
- <script>
- // var json;
- // $.ajax("AppstoreWS.svc/getPlatforms", {
- // beforeSend: function (xhr) {
- // // $.mobile.showPageLoadingMsg();
- // },
- // complete: function () {
- // // $.mobile.hidePageLoadingMsg();
- // },
- // contentType: 'application/json',
- // dataType: 'json',
- // type: 'GET',
- // error: function () {
- // alert('Something awful happened');
- // },
- // success: function (data) {
- // json = data.getPlatformsResult;
- //
- // }
- // });
- //$.urlParam = function(name){
- //var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
- //return results[1] || 0;
- var json1 = {
- "results": [{
- "term": "Term One",
- "definition": "This is the definition for Term One"
- }, {
- "term": "Term Two",
- "definition": "This is the definition of Term Two"
- }, {
- "term": "Term Three",
- "definition": "This is the definition for Term Three"
- }],
- "ok": "true"
- };
- var json = {
- "getPlatformsResult":
- [{ "FolderName": "Android" },
- { "FolderName": "UltimateRewards"}]
- };
- var currentItem = 0;
- $('#glossary').on('pageinit', function () {
- $.each(json.getPlatformsResult, function (i, output) {
- $('#resultsList').append('<li><a href="#display">' + output.FolderName + '</a></li>')
- });
- $('#resultsList').listview('refresh');
- $('#resultsList li').click(function () {
- currentItem = $(this).index();
- });
- });
- $('#display').on('pagebeforeshow', function () {
- $(this).find('[data-role=header] .ui-title').text(json.getPlatformsResult[currentItem].FolderName);
- // $('#definition').html(json.getPlatformsResult[0].FolderName);
- $.ajax("AppstoreWS.svc/getPlatforms", {
- beforeSend: function (xhr) {
- $.mobile.showPageLoadingMsg();
- },
- complete: function () {
- $.mobile.hidePageLoadingMsg();
- },
- contentType: 'application/json',
- dataType: 'json',
- type: 'GET',
- error: function () {
- alert('Something awful happened');
- },
- success: function (data) {
- result1 = data.getPlatformsResult;
- $('#categoryList').children().remove('li');
- $.each(result1, function (index, output) {
- $('#categoryList').append('<li><a href="?cid=1234&sid=test#display2" >' + output.FolderName + '</a></li>');
- });
- $('#categoryList').listview('refresh');
- }
- });
- });
- $('#display2').on('pagebeforeshow', function () {
- $(this).find('[data-role=header] .ui-title').text(json.getPlatformsResult[currentItem].FolderName);
- // $('#definition').html(json.getPlatformsResult[0].FolderName);
- alert('Page 2 - CID: ' + getParameterByName('cid'));
- // alert('Page 2 - CID: ' + getParameterByName('sid'));
-
- // alert($.urlParam('cid'));
- // alert(getParameterByName('cid'));
- $.ajax("AppstoreWS.svc/getPlatforms", {
- beforeSend: function (xhr) {
- $.mobile.showPageLoadingMsg();
- },
- complete: function () {
- $.mobile.hidePageLoadingMsg();
- },
- contentType: 'application/json',
- dataType: 'json',
- type: 'GET',
- error: function () {
- alert('Something awful happened');
- },
- success: function (data) {
- result2 = data.getPlatformsResult;
- $('#categoryList2').children().remove('li');
- $.each(result2, function (index, output) {
- $('#categoryList2').append('<li> <a href=#category-items?category=' + output.FolderName + '>' + output.FolderName + ' </a></li>');
- });
- $('#categoryList2').listview('refresh');
- }
- });
- });
- $.urlParam = function getParameterByName(name) {
- var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
- return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
- }
- function getParameterByName(name) {
- var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
- return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
- }
- </script>
- </body>
- </html>