Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript Ajax jQuery
hi,

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++)
{
$.ajax({
                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 2:54am
Edited 26-Nov-12 19:41pm
v10
Rate this: bad
good
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..
  Permalink  
Comments
Killzone DeathMan at 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 at 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 chrome..it 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 at 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: miguel.poegel@pears.fr
saurabh bisht at 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 at 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 at 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 this...as 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
good
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..
 
thanks
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,105
1 DamithSL 5,079
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,617
4 Kornfeld Eliyahu Peter 4,384


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
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