In order to avoid device slowdown and crash application, I'm using the JQM single page navigation model because it allows auto DOM size management.
I'm dynamically injecting pages using href="page.html" into the DOM as the user navigates and manually using changePage('page.html') to handle user interactions.
So, as far as I'm conerned, on those pages that use server-data I need to:
1) Load (inject) new page into the DOM to access target divs/containers 2) dinamically place new data (append)
Please, take a look into this example for illustrative purposes:
function loadData (myJSONObject){
// inject page $.mobile.changePage('page2.html');
//load data for(var i=0; i<myJSONObject.data.length;i++){ name = myJSONObject.data[i].name; link = myJSONObject.data[i].description;
// #listData is the target container from page2.html $("<a />",{ text: name, href: link }).appendTo( $("<li />",{ id: name, }).appendTo('#listData')); }
This code results in an empty list because the JQM page injection function(s) takes longer than loading data due to javascript asynchronous behaviour
**Note that: - using multipage model and changePage('#target') works - testing with setTimeOut() and forcing the data loading loop to wait also works but I assume that is not optimal neither a good developing practise
QUESTION: Is there a callback or way to start loading data only when new page is fully injected into the DOM so does target container availability?
I'm an entrepreneur from Madrid working on a social startup.
I'm using jqueryMobile framework + phonegap to develop an app.
I'm dynamically injecting pages using href="" into the DOM but it seems that Chrome do not handle $ajax based JM single page navigation model. I get an error loading page message and this error from the tool developer console while clicking on the navMenu: XMLHttpRequest cannot load file:///C:/git/app/myapp/assets/www/html/page2.html. Origin null is not allowed by Access-Control-Allow-Origin.
Probably it has to do with cross-border petitions, but I can't find how to solve it.
I don't want to disable $ajax petitions because then it won't auto generate some useful functionality like DOM size management (avoid device slowdown that causes crash), <back> button and transitions.