Click here to Skip to main content
13,140,023 members (49,052 online)
Rate this:
Please Sign up or sign in to vote.

i have problem regading my asyc calls using ajax with jquery....

the code is like:

$("#loading").css("display", "block");
for(i=0; i < aValue; i++)
                url: '/link1/getdata',
                type: "GET",
                cache: false,
                async: false,
                data: {data : i}
               success: function(result) {
                   $("#loading").css("display", "none");

this works well for mozilla...but "
async: false
" doesnt works properly in google chrome..

if "
async: false
" then in chrome the loading img does not appear ..

please help me on this..
Posted 22-Nov-12 1:54am
Updated 26-Nov-12 18:41pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi Saurab,

May be you just spelled your image's id wrong.. it should be "#loading" in place of
"#loadimg"..check it out..
see if it works..
Killzone DeathMan 26-Nov-12 4:44am
Maybe its a good answer, but certainly its an unsecured answer!
How do you know the id of the loading image is "loadimg" ?
saurabh bisht 26-Nov-12 6:02am
no the problem is not with image name at all...
the problem is that mozzila treats asyn calls in seperate thread so the image is visible...but in case of is not like that....if the above code is in a for loop then it happens so fast that it skips the img show/hide....i still dont have a solution for this..
Killzone DeathMan 26-Nov-12 6:41am
My friend, I do not know your purpose, but this code doesn't do anything, you just do the same thing aValue times only for hide one thing!
There are 2 threads running on your code, the i variable are incrementing fast, and the ajax are still waiting for a response!
Just tell me what you want to do and if you want, we can talk per gtalk:
saurabh bisht 26-Nov-12 8:20am
yes exactly..there are two threads..
but in case of chrome "async = false" doesnt seem to synchronize with the other thread which is of the loop...

loop is not the same....each every time the value changes... it is assigned to data which is send via url to hit DB on that particular value of data..
sorry i did not mentioned " data: {data : aValue} "in the code..
Killzone DeathMan 26-Nov-12 9:35am
That makes no sense.. I dont know your purpose.. " data: {data: i}" makes more sense...
Just go to gtalk, I already add you to my chat...
saurabh bisht 27-Nov-12 8:35am
brother thanks for your efforts...but we still could not come to the exact scenario....but any ways i resolved this issue and would soon write an article on it would be help full for those who get the data from controller using ajax jquery..where the data fetching is huge and the time delay is large..thanks killzone..
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

in the above code there are two threads working in the background....

one is for the for loop..

another thread for the "success" field of ajax..untill the data is extracted from the controller..

the thread with the for loop gets finished as a normal for loop finishes...

but the browsers maintans a queue of the ajax "success" and execute them seperately one by one....

also(in this case) any javascript command would not work out of the ajax call because when the forloop was being iterated by one thread then it had already executed the whole script...what was remaining in the back ground was the queue of dates data and the rendering of page.

understanding this flow one can adjust his code accordingly..


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100