JQuery mobile preload page loading content via Ajax

I use jQuery mobile in a single page template (each page is a separate html file). I want to pre-select a page that loads content through Ajax. I put the prefetch code in the Document.ready () function on the first page

$.mobile.loadPage("my-projects.html", { showLoadMsg: false }); 

ajax call inside the Document.ready () function of the second page that I want to pre-program. This ajax call does not happen when we prefix this page. Is there any way to achieve this. Please, help

+6
source share
1 answer

jQuery Mobile has built-in prefetching, all you have to do is add the data-prefetch attribute to the link that links to the remote page:

 <a href="prefetchThisPage.html" data-prefetch> ... </a> 

Source: http://jquerymobile.com/demos/1.1.0/docs/pages/page-cache.html

In general, when you pull a page through AJAX, the document.ready function will not . However, you can use jQuery events for mobile pages, such as pageinit . For instance:

 $(document).delegate('#my-page-id', 'pageinit', function () { $.mobile.loadPage("my-projects.html", { showLoadMsg: false }); }); 
+1
source

Source: https://habr.com/ru/post/918188/


All Articles