I have a small problem with making synchronous Ajax call,
1) I have to hit server by making ajax call in for loop, am having 5-10 values in Array to iterate,
for each iterate am placing constructing some html and placing in variable with respect to request,
2) Here problem is it is overriting all values with last value.
3) I thought of making it sync ajax call to wait until this request is processed , but with synchronous call it is not going to ready state change method.
code snippet :
Could you please let me know where it went wrong?
Really appriciate if any ideas..
How can you expect us to help you with a code snippet that has nothing to do with the problem you described.
1) You say you have a for loop, but you didn't know us the for loop. Without that context of understanding we cant help.
2) You say it is overriding values but you just have a comment in the place where the work is being done. No code == no way we can help
3) Again, not enough code to determine what your problem might be.
So all you need to do is to wait for a request to finish before sending the next one.
Ping & DNS - updated with new look and Ping home screen widget
Joined: Nov 08, 2001
Well you are using a local variable so the call problem appears to be a different issue.
That has a global variable problem, it needs a var
You need to do some debugging to figure out where the values are being overwritten.
Firebug and console.log will be your friend.
Joined: Oct 12, 2007
I got the problem with Synchrnous ajax call, for these kind of request we should not use response handler ( like onreadystatechange handler ), for async calls we have to take response once we give request immediately ( by using req.responseText() ).
The doAjaxCall is executed many times in a loop,
Mostly you would expect that when the doAjaxCall function completes, the next iteration is made,
However, you may be wrong in one case...
indicates that the Business logic code will execute in 'its own sweet time'
there is no guarantee of order here,
AJAX calls are inherently asynchronous, which means that supposed your business logic printed "hi" in one execution and "bye" in another,
in the example you provided, there is no guarantee where "hi" would be printed first or "bye"
As Ulf Dittmer rightly stated, you need to wait for a request to finish