codeandcloud
codeandcloud

Reputation: 55248

Calling Webservices in a loop won't execute the custom OnSuccess function

I have a problem. I am coding using VS2008. I am calling webservices from my JavaScript Page. An example

Services.ChangeDropDownLists.GetNowPlayingMoviesByLocationSVC(
    blah, 
    OnSuccessMoviesByRegion, 
    OnError, 
    OnTimeOut
);

after execution, it goes to the function OnSuccessMoviesByRegion.

But if I put the Services in a loop (a simple for loop)

Services.ChangeDropDownLists.GetNowPlayingMoviesByLocationSVC(
    blah[i], 
    OnSuccessMoviesByRegion, 
    OnError, 
    OnTimeOut
);

OnSucessMoviesByRegion function won't execute (but the service call executes n times successfully But I must have the function cos I am returning value through it.

What am I missing? Is that the typical behaviour? Any alternatives?

Upvotes: 1

Views: 611

Answers (2)

splattne
splattne

Reputation: 104050

Naveen, I'm answering your follow-up question here. I can think of two options:

  1. Try to make a single call packaging your data (sending the whole blah array and handle it on the server).

  2. Use a counter variable which you decrement in the "OnSucces" client handler each time and stop if this counter variable reaches 0.

Upvotes: 1

splattne
splattne

Reputation: 104050

I guess there is some kind of concurrency problem. Probably you fire the next request before the last one finished.

I think you'll have to rewrite the loop. Try to move that code, calling only the first request and then using the "OnSuccess" function to call the next one each time.

Upvotes: 1

Related Questions