views:

40

answers:

1

Hi, I'm trying create a box in my Django app that displays text (and possibly images) from the server as certain processes are completed server side. I was hoping to use a plugin that used Dajax / Jquery but I'm unable to find one. Is there a solution out there that is simple? Thanks.

+2  A: 

I you don't really need a plugin for something like this. It should be fairly simple to create something yourself.

Since the process is happening server side, you need to figure out when the server is done with a part, has some data to display etc. setInterval works just fine for that, with it you can ping your server every x seconds and handle the result. The code would look something like this:

$(document).ready(function() {
  function ping() {
    $.getJSON('get/your/ajax', function(json) {
      if (json.status === 'ready') {
        // Do your thing, with the data sent.
      };
      else if (json.status === 'done') {
        // Stop pinging server when you're done.
        clearInterval(interval)
      }
    });
  };
  interval = setInterval('ping()', 2000);
});
googletorp