Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my method for dynamically adding content to my Jquery Mobile websites:</p> <ol> <li><p>First I create a "wrapper" data-role=page div like so:</p> <pre><code>&lt;div data-role="page" id="my_page_id"&gt; &lt;div data-role="content"&gt; &lt;script&gt; $('#my_page_id').live('pageshow', function() { my_data_loading_function('my_page_id'); }); &lt;/script&gt; &lt;div id="my_page_id-content"&gt;&lt;/div&gt; &lt;/div&gt;&lt;!--/content--&gt; &lt;/div&gt;&lt;!--/page--&gt; </code></pre></li> <li><p>Next I load data from an external source into a div tag located in my "wrapper" page: </p> <pre><code>function my_data_loading_function(page) { if ($('#' + page + '-content').is(':empty')) { $.mobile.pageLoading(); $('#' + page + '-content').load("my_external_script.php", function() { $.mobile.pageLoading(true); $('#' + page + '-content ul').listview(); $('#' + page + '-content ul').page(); }); } } </code></pre></li> </ol> <p>Some Notes:</p> <ul> <li><p>$.mobile.pageLoading(); and $.mobile.pageLoading(true); show and hide (respectively) the Jquery Mobile loading spinner.</p></li> <li><p>if ($('#' + page + '-content').is(':empty')) { allows the user to navaigate away from the dynamically created page and then come back and not have to re-load the data until a full page refresh occurs.</p></li> <li><p>My dynamically created page included mostly a list so listview() makes the jquery mobile framework refresh the list selected to add the proper css, page() does the same to other page elements; however you may only need to use one or the other depending on your content (or none at all if its just plain text).</p></li> <li><p>I realize this isn't creating a whole page dynamically because the "wrapper" page is already hard-coded but if you want to add a whole new page you can probably use something like: (untested)</p> <pre><code>$(document).append('&lt;div data-role="page" id="my_page_id"&gt;&lt;div data-role="content"&gt;FOO BAR&lt;/div&gt;&lt;/div&gt;'); $('#my_page_id').page(); </code></pre></li> </ul> <p>If you really want to make it all dynamically created you can check for window.location.hash and create your data-role=page div with the id set as the window.location.hash.</p> <p>Also I am using Jquery 1.6 and Jquery Mobile 1.0a4.1</p> <p>I hope something in there can help someone out there :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload