Hi Guys,
I have buttons defined in the following manner:
<input id="405,23272-200,233" class="addbutton" type="submit" value="Add"/>
and some javascript to update parts of the page on a button being clicked:
document.observe('dom:loaded', function () {
$$('.addbutton').each(function(item) {
Event.observe(item, 'click', function(event) {
new Ajax.Request('/neighbouring?.state=add_cell&add=' + item.id + '&dummy='+(new Date()).getTime(),
{ method: 'post',
onComplete: function(transport) {
var cell = transport.responseJSON;
var elupdates = document.getElementsByClassName('update_on_add');
for (var i = 0; i < elupdates.length; i++) {
var upid = elupdates[i].id;
//alert(upid + " : " + cell.Source);
var oUpd = new Ajax.Updater(upid,'/neighbouring?.state=update_template&divid=' + upid + '&source='+ cell.Source + '&updummy='+(new Date()).getTime(),{method: 'post'});
}
}
});
}, false);
});
});
The Ajax.Request and Ajax.Updater callbacks are triggered at the same time, not after another - as expected :-(
I had a similar problem at http://stackoverflow.com/questions/1376059/ajax-request-and-callback-update-are-triggering-at-the-same-time - but i can't see how it applies to this problem ?
If, instead of putting the Ajax.Updater requests in the for loop( as above), i rather embed them within one another, like below :
var b= new Ajax.Request('/neighbouring?.state=update_template&divid=cell_summary&source='+ cell.Source + '&updummy='+(new Date()).getTime(),
{
onComplete: function(response1) {
var elm = response1.getHeader('Element');
$(elm).update(response1.responseText);
var c= new Ajax.Request('/neighbouring?.state=update_template&divid=rule7_check&source='+cell.Source + '&updummy='+(new Date()).getTime(),
{
onComplete: function(response2) {
var elm2 = response2.getHeader('Element');
$(elm2).update(response2.responseText);
//var c = new Ajax.Request ... yada yada yada
}
});
}
});
Then the whole thing works. Could it be that simultaneous Ajax.Updater responses are not handled properly inside the Prototype library (using 1.6.03.) ?