user2158259
user2158259

Reputation: 137

jquery mobile - loadPage issue

I am having trouble getting jQuery-mobile load page to load my next page into the "content" div.

I have cut my page down to the basics and here is the code.

index.html:

<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>JQuery Mobile Load Page Test</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>
<body>

<div data-role="page">

    <div id="containerTest" data-role="content">

        <input type="button" id="nextPage" data-inline="true" value="Load Second Page"/>

    </div> <!-- /content -->

</div> <!-- /page -->

<script>

    $( "#nextPage" ).on( "click", function()
    {
        $.mobile.loadPage("nextPage.html",
        {
            pageContainer: $('#containerTest')
        });
    });

</script>

</body>
</html>

and nextPage.html

<div data-role="page">

    <p>this is the next page</p>

</div> <!-- /page -->

Upvotes: 2

Views: 2535

Answers (1)

omma2289
omma2289

Reputation: 54619

I don't think You can load a page inside another page, you could try something like this though:

$(document).on('pageinit', function(){
    $( "#nextPage" ).on( "click", function(){
        $('#containerTest').load('nextPage.html [data-role="content"]',function(){
            $('.ui-page-active').trigger('create');
        });
    });
});

This will load the content (<div data-role="content">) from page 2 inside the container, then it will trigger the create event on the original page to enhance the loaded content

Upvotes: 1

Related Questions