[Django]-Jquery mobile and dynamic page content

0👍

just to update my experience of this.

so in the end i spent most of my time scratching my head with jquery mobile. of course if i had rtfm’d beforehand i would have probably had a smaller headache out of it all! basically the ajax page updates were just plain annoying, so the important thing here would be to disable them using rel="external" or data-ajax="false" on my html form – and, because of the way #’s are used, you will also want to add these tags to any pages that load up this page also (otherwise the multipage won’t work properly).

i then created a multipage jqm page and link to it via my submit button (in my case with data-rel="dialog"), with the second page with an empty iframe; i set the form target to this iframe and voila! it works! the streaming result from the form submission shows up as it should.

so to sum it up:

  • django HttpResponse is returned, where its argument is a generator object. this enables the streaming nature of the output.
  • create the jqm page:

    <div id="main" data-role="page">
      <div data-role="content">
        <form id="myform" method="post" target="response-iframe" action="***django generator page***" data-ajax="false">
          ...
          <a id="submit-button" href="#secondary" data-rel="dialog" data-role="button" data-theme="e">Submit</a>
          <script>
          $('#submit-button').live( 'click', function(){
              $('#port-form').submit()
            })
          </script>
        </form>
      </div>
    </div>
    
    <div id="secondary" data-role="page">
      <div data-role="content">
        <iframe id="response-iframe"></iframe>
      </div>
    </div>
    

👤yee379

0👍

You can poll Django for progress updates using usual AJAX requests.

It don’t solve the jquery mobile and long polling problem, but it gives you flexibility needed to put your long running task away from the frontend and into the backend (for example using Celery).

To maintain performance I recommend updating status from the long running task to a memcached instance.

In your view just fetch the progress and return i.e. which will fire the dialog box or update some div. Better yet – just the results.

Leave a comment