Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,

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

the code is like:



C#
$("#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 "
C#
async: false
" doesnt works properly in google chrome..

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

please help me on this..
Posted
Updated 26-Nov-12 18:41pm
v10

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..
 
Share this answer
 
Comments
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 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 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 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...
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900