I am working with jquery mobile and I am trying to pass variables within the same page.
<a href="page2.html?var1=foo&var2=bar">link1</a>
<a href="page2.html?var1=something&var2=bbq">link2</a>
After clicking on the link the page will be placed into the DOM. I understand that I will have to reload the page to allow for the new variables to be applied, but I have not been successfull doing this with the:
$.mobile.changePage("page2.html", {reloadPage : true,});
When the page loads I am using the following:
$(document).delegate('#page2','pageinit', function(){
$.mobile.changePage("page2.html", {reloadPage : true});
});
The above code will just take the page in a forever loop, which is obviously not what I want. I tried to take the changePage out side of the pageinit, but the reason for needing it inside the pageinit is for the back button to work. So then I thought that that maybe I could get the variables from the url, so I tried the following with the use of the jqm.page.params.js:
$(document).delegate('#page2','pageinit', function(){
if ($.mobile.pageData && $.mobile.pageData.proj_id){
console.log("Parameter var1=" + $.mobile.pageData.var1);//does not print at all.
}
console.log("Parameter obj =" + $.mobile.pageData); // prints NULL
});
I found in the documentation a link to the plugin which is suppose to allow you to use the parameters in the url called jqm.page.params.js but there is no examples on how to use this plugin.
Is there anyone here that knows how to use this plugin? Or is there a better way on passing variables when you are on the same page linking to the same page but with different variables?