user1253869
user1253869

Reputation: 1

how run code asynchronously in jquery mobile

I need prefetch internal page in JQM, when i call

$.mobile.loadPage("#pedido");

this code run in synchronous mode, ui wait for this. Please, How i can run this code in asynchronously mode?

I have api function for create this page, could run the function asynchronously?

Thanks,

Upvotes: 0

Views: 776

Answers (1)

DdD
DdD

Reputation: 453

Personally, I prefer running that synchronously, but if you must you can just try use a simple timeout

setTimeOut(function() {
    $.mobile.loadPage("#pedido");
}, 50);

But I can't imagine why you would want to do this.

I use the pagebeforeshow event in jQM (maybe this example will give you some idea)

    <div data-role="page" id="thePageID">
       ...blablabla...
    </div>

    <script type="text/javascript">
       $('#thePageID').on('pagebeforeshow',
          function(event) {             
          /* do your page stuff here */
       });            

    </script>

and just use $.mobile.changePage(pageName); so it will call the pagebeforeshow function before anything happens, once pagebeforeshow is completed, then the page will be displayed.

Upvotes: 1

Related Questions