View Full Version : Looping service call

26 Aug 2013, 4:35 AM
I am using ExtJS and Springs to develope application..
Following ExtJS MVC pattern..

Suppose I have an List of 10 Object. I want to loop and make service all by sending One object at a time. I want to send second object only when the service call for first object is successful..

How can I loop and make the service call..?

26 Aug 2013, 11:44 AM
Create an array of objects to send, pop one off the stack and make an ajax request.

In your callback, look @ the stack and if length > 0, pop the next one off and so on. If the length is 0, then you've reached the end.

26 Aug 2013, 8:55 PM
Thanks Jay.. Got an idea...

26 Aug 2013, 9:05 PM
Popping up from stack makes sure we send all objects one by one.. But what about the response???
I want to send send object only when first object response is successful..

26 Aug 2013, 9:18 PM
The process is exactly the same:

function doRequest(items) {
if (items.length) {
url: 'foo',
params: {
id: items.shift()
success: function() {
// do stuff

var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

24 Sep 2013, 8:23 AM
Awesome.. This example code is perfect... Thank you very much... =D>