PDA

View Full Version : How to solve multiple ajax request



just_a_kid
26 Oct 2010, 5:01 AM
Hi,

I would like to know how to solve multiple ajax request.

It seems that this is a maximum browser connection issue.

If i call Ajax.request scripts sequentially a lot of times ( because it's needed as i need to render different data from different source in one page ) one / all of them might have a chance go to failure block

Any advice / workaround for this ?

Thanks

httpdotcom
26 Oct 2010, 7:49 AM
- combine multiple requests into single when possible,
- use success handlers to organize requests sequentially, or use failure handler to display appropriately,
- or solve the problems with failures; if you don't control the data, find the best possible way to ensure it is available (pre-load)

just_a_kid
28 Oct 2010, 11:48 PM
Thanks for the insight

I am more interested into the second one , but how to do it effectively?
i don't want it to be become very nested code for example if i have to execute 10 ajax request independently without hitting the maximum browser connection issue

let's say execute at most 2 ajax request asynchronously , after one of them go to success handler , execute the rest?

How to design these things ? any reference / sample code on how to do this ?

Thanks

Animal
29 Oct 2010, 12:59 AM
In the success handler, call the function which handles the next request. Simples.

httpdotcom
2 Nov 2010, 6:15 PM
Ext.Ajax.request( {
config options
,success: function ( response, opts ) {
var jsonData = Ext.util.JSON.decode( response.responseText ) ;
var resultMessage = jsonData.data.result ;
do something else
} ) ;