Hi guys,

I'm looking for some help on allowing controller functions to respond
to ajax calls from a view in parallel. I've got my head around the
basic web2py architecture, but this is my first time trying out ajax
in web2py.

Here's the problem. I have a simple view that makes a number of ajax
calls, to provide delay loading of data. The results are from querying
and parsing URLs on demand, so they can be slow. The controller
function I am calling (default/results_data) appears to be blocking,
only executing one request at a time. This obviously defeats the
purpose of delay loading the data on the page.

I have made sure I am running the web2py app locally with the -n
option (for threads), but this isn't the issue. I have found the
session.forget() call, but this isn't it either.

I am guessing there is something fundamental that I am doing wrong
here, I am hoping someone can clarify what is required to allow the
controller functions that respond to the ajax query to execute in
parallel, without blocking.

A snippet from the html generated by the view:

function sendRequest(url,callback,postData) {
        try {
                var req = createXMLHTTPObject();
                if (!req) return;
                var method = (postData) ? "POST" : "GET";
                req.open(method,url,true);
                req.setRequestHeader('User-Agent','XMLHTTP/1.0');
                if (postData)
                        
req.setRequestHeader('Content-Type','application/x-www-form-
urlencoded');
                req.onreadystatechange = function () {
                        if (req.readyState != 4) return;
                        if (req.status != 200 && req.status != 304) {
                                alert('HTTP error ' + req.status);
                                return;
                        }
                        callback(req);
                }

                if (req.readState ==  4) return;
                req.send(postData);
        }
        catch (e) {
                throw e;//alert(e);
        }
}
...
<script>
function source1_results(req)
{document.getElementById('query1_results').innerHTML =
req.responseText;}
sendRequest('/myapp/default/results_data?
query=foo&source_name=source1', source1_results)
function souce2_results(req)
{document.getElementById('source2_results').innerHTML =
req.responseText;}
sendRequest('/myapp/default/results_data?
query=foo&source_name=source2', source2_results)
</script>
...
<table>
<tr><td>source1</td><td id="source1_results">Loading...</td><td><a
href="http://...";>View page</a></td></tr>
<tr><td>source2</td><td id="source2_results">Loading...</td><td><a
href="http://...";>View page</a></td></tr>
</table>

Reply via email to