durusmail: quixote-users: Displaying results of a processor intensive operation in increments possible under quixote?
Displaying results of a processor intensive operation in increments possible under quixote?
2004-11-18
2004-11-18
2004-11-19
2004-11-19
Displaying results of a processor intensive operation in increments possible under quixote?
Graham Fawcett
2004-11-19
Here's another suggestion, but it has more to do with DHTML than with
Quixote specifically.

If you have some control over what browsers will be used, and can be
assured that they are fairly new versions of fairly mainstream
browsers, then you can also use a "background XML import" to fetch
your data incrementally, and rebuild parts of your currently-displayed
Web page based on the XML that you fetch. The idea is that your "main
page" would essentially be a shell, and that in a Javascript
setTimeout() loop, you repeatedly request updates from your Quixote
app, and use the updates to populate the shell.

Note: Your server would have to execute the long-running process in a
separate thread of control (a thread or child process, for example)
and store the current state of the results, so that multiple HTTP
requests could all access the results.

If, for example, you've loaded your "main page", and the JavaScript
has done an initial fetch from your "results URL":

..../results/fetch

and have received 30 results so far, you could later request

...../results/fetch?since=30

to see if any more results have been processed.

It's possible to have the "results/fetch" response actually return a
chunk of (X)HTML that you could then inject into your "main page",
e.g. adding rows to the bottom of an existing table. Otherwise, you'll
have to return some kind of XML document representing your results,
and use JavaScript/DOM to parse the document, and dynamically generate
new HTML content for your page.

Designing such an app is outside the scope of Quixote; the same
technique could be applied with any framework. You can get some ideas
by Googling for:

    document.implementation.createDocument XMLDOM

There's also a nice introductory howto at

    http://www.quirksmode.org/dom/importxml.html

As a last heads-up: if you try this technique, be sure that your
"results/fetch" URL, or any other URLs that are to be read "in the
background" by JavaScript, have an explicit Content-Type of "text/xml"
or some other XML content-type; otherwise, some browsers will not
honour the response and you'll get errors in your JavaScript code.
Also be sure that the response is valid XML/XHTML for the same
reasons.

I'll provide sample code if someone is interested in this technique.

BTW -- Jonathan, it's nice to see there's a Quixote user at another
Canadian university!

-- Graham 

reply