Last day I had to hack a webshop's basket management system, and deleting the items had to be done via AJAX. The problem was, that each call had to wait the previous to be completed, otherwise some products kept in the session. The solution was simple: call the AJAX requests recursively on the 'onComplete' event.
Here is a cleaned up code, using MooTools 1.2.4. Call addAjaxParam() to prepare the ajaxParams array.
var ajaxParams = [];
function addAjaxParam( pid )
{
var obj = {
'option': 'module_shop_action',
'product_id': pid
}
ajaxParams.push( obj );
}
If the program reaches the event when the AJAX calls can be triggered, call ajaxAction( 0 );
function ajaxAction( id )
{
if( ajaxParams[ id ] )
{
var request = new Request({url: 'ajaxserver', onComplete: function(){
ajaxAction( id+1 );
}});
request.post( ajaxParams[ id ] );
}
}
// Execute the first parameter in the ajaxParams array.
ajaxAction( 0 );
All rights reserved, ©2008-2010 - Built on CodeIgniter framework - Konami codes - Mostly Valid XHTML 1.1 - Valid CSS 2.1