PDA

View Full Version : Ajax request queue or wait for another listener



Snoop74
30 Oct 2010, 1:53 AM
Hello all.

I have a little bit complicated problem:

* There ist an ajax request, which gets f.ex. 5 records
* In the "success" event, for every of those 5 record another request has to be called
(there is no other way, because this 2nd ajax request will use another server and params from each of the 5 recs)
* Those new request has its own "onload" listener
* The results have to be displayed in a panel - each one.

Now my problem:

I can only show the results after receiving the results from the 2nd request within those listener.
But i get lost of the linking information.

Fully code is too complex, but i'll try to give yo an example:



function onAskLoad(h) {
if (h.Status == 200) {
var html = Ext.getCmp("statusPanel").html + "<br />";
Ext.getCmp("statusPanel").update(html + "value = " + h.value);
}
}

function getInfo(recID) {

// Here a new request will be created - pls acceppt this "small" version
// There are no other listeners or functions like "wait", ... only the "load" event listener
var ask = new ...
ask.addListener("load", onAskLoad);
ask.load("url_with?recID");

}

Ext.Ajax.request({
url: 'getrecords.php',
params: {
"action": "getDetails",
"list": "1,2,3"
},
success: function(response) {
var obj = Ext.decode(response.responseText);

// For every given record a function will be called:
for (every_single_recordID_from_obj_array)
getInfo(recordID);
}
});

Now, there it's a complete chaos.

How can I display each result after the other ?

Best option (my wish):

* show all records in a panel:
A - B = Wait ...
C - D = Wait ...
K - M = Wait ...
* get all results step-by step and show them in the list:
A - B = OK
C - D = Wait ...
K - M = Wait ...

A - B = OK
C - D = Not ok
K - M = Wait ...

[...]

Has somebody an idea ?