Hope you all are fine and rocking your code editors.
My question is how to pass url rel to a new page to use it in future?
Let me give you an example that will work better than 1000 words.
On page “A” I have url to page “B”, to load page “B” html I pointing that url straight to page “B” as <a href="page-B.html" rel="{{id}}">{{deptName}}</a> (don’t look at {{}} it is Mustache.js tags).
So when I am clicking on that link it is working as it should, pointing me to page “B” and loading my new html layout (that is different from page “A”).
Now because I am fetching data from JSON I need to pass rel="{{id}}" to a page-B to tell what data I want from the JSON.
Any good ideas or practical code how you do that?
Thank you!
P.S.
On page “B” in $.delegate I need that id to do something like that:
$.ajax({
beforeSend: function() { $.mobile.showPageLoadingMsg() }, //Show spinner
complete: function() { $.mobile.hidePageLoadingMsg() }, //Hide spinner
url: 'http://website.com/categoryJSON.ashx?&catId=THE_ID&callback=?',
dataType: 'json',
success: function(data) {
var template = $('#pageCategoryTpl').html();
var html = Mustache.to_html(template, data);
$('[data-role=content]:first').html(html);
}
});
I found a simple solution and it is window.sessionStorage.
In my particular case scenarion I am clicking on URL/link, getting href (this where my id is), saving that with window.sessionStorage, changing window.location to the new page and do my JSON magic.
The code:
On page “A”:
On page “B”:
Vuala! Hope that will help someone.