JQuery Mobile second page loading from new html

Let's say I want to load a new html file with some jQuery pages, for example:

$.mobile.changePage("some_page.html"); 

If this html file contains two pages inside, how do I load not the first but the second page? I tried

 $.mobile.changePage("some_page.html#second_page_id"); 

But that will not work. Thanks

+4
source share
4 answers

The $.mobile.changePage() function takes the first div with data-role="page" and loads it into dom with an AJAX call. The best solution is to move the second page to the top of the html code.

Otherwise, if you want to decide to load the first or second page, you can put them in different files.

Maybe there is a way to invoke the second page, but I don't know how to do this.

0
source

Dude will try to make your second element of the data-url page as <div data-url="page.html&subpageidentifier"> on the html landing page. and let me know, it really worked for you.

0
source

You can manually capture the required item:

 //delegate the event binding for some link(s) $(document).delegate('a.my-link', 'click', function () { //show the loading spinner $.mobile.showPageLoadingMsg(); //make the AJAX request for the link href attribute $.ajax({ url : this.href, success : function (serverResponse) { //get the data-role="page" elements out of the server response var $elements = $(serverResponse).find('[data-role="page"]'); //you can now access each `data-role="page` element in the `$elements` object $elements.filter('#page-id').appendTo('body'); //now use changePage to navigate to the newly added page $.mobile.changePage($('#page-id'), { /*options*/ }); //hide the loading spinner $.mobile.hidePageLoadingMsg(); }, error : function (jqXHR, textStatus, errorThrown) { /*Don't forget to handler errors*/ } }); //stop the default behavior of the link, also stop the event from bubbling return false; }); 

But I have to say that with the way jQuery Mobile works, you better place each data-role="page" element in a separate document.

0
source

ทำ แบบ น ี้ ครับ

<a href="../index.php#two" data-ajax="false" data-transition="fade" data-role="button" data-theme="e" name="out">ออก</a>

สำคัญ คือ ให ้ ใส่ data-ajax = "false"
คุณ ก็ จะ changepage ได ้ จาก ต่าง หน ้ า

0
source

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


All Articles