PDA

View Full Version : Asynchronous requests / ProgressBar



jamesfarrer
22 Feb 2008, 6:20 AM
Hi,

I have a grid a checkbox per row, the user then selects as many as they like, clicks on a button and an action then happens.

I thought I'd try to be clever - the grid could contain several hundred records, so rather than just pass through one big array, pass each checkbox value one at a time via AJAX and display a progress bar with an update. However I seem to run into a problem - some of the requests fail instead of succeed - even though it should (and always does) return successful.

The error I get is non-descript one "communication failure" rather than a HTTP error code.

My code is as follows



for (j = 0; j < selectedMsgs.length; j++)
{
Ext.Ajax.request({url:"../messagerecovery/send.castle",params:{msgId:selectedMsgs[j]+''},success:sendComplete,failure:sendFailure});

}


The above just loops through an array of values and sends the request



function sendComplete(conn,response,options)
{
sendCurrentMsg = sendCurrentMsg + 1
sendProgressBar.updateProgress(sendCurrentMsg/sendCurrentTotal, 'Sent message ' + response.params.msgId + ' (' + sendCurrentMsg + ' of '+sendCurrentTotal +')');
}


sendCurrentMsg + sendCurrentTotal are global variables.

Am I doing this correctly? I am unsure if I should be attempting to do synchronous requests, but I see everyone in these forums does not recommend that.

[/CODE]

hendricd
22 Feb 2008, 7:19 AM
@jamesfarrer -- Your request pattern is trying to make too many requests at the same time. The browser enforces limits on such attempts.

Slow things down a bit, and let the browser catch up (and render your progress bar changes smoothly).

See if this asynch pattern (http://extjs.com/forum/showthread.php?p=120278#post120278)does the trick for you.