views:

46

answers:

2

Hi there,

I have problem with Google Chrome or rather Androids (2.1) webbrowser.

My webapp calls restservices with each page shift. This takes some time and I need a feedback for the user like a little "working..." popup . The restservices are called with a sync ajax request. Here is an example:

$.ajax({
    url: some URI,
    async: false,
    beforeSend: function() {
        showIndicatorDialog();
    },
    complete: function() {
        hideIndicatorDialog();
    },
    success: function(response) {
        do something after success;
    },
    error: function(response) {
        do something after error;
    },
    type: 'GET'
});

That works great on FF and Opera! But when I visit my webapp on Chrome oder with my Android device the loading indicator doesnt appears! It seems that the Google browser don't work with synchrchronous requests.

Does someone know how I can get this to work or knows another solution to get a loading indicator in chrome??

+2  A: 

The solution is not to use synchronous requests. In general, synchronous requests should never be used because they tend to block the execution of anything else on the page (or even the entire browser UI), which isn't good.

Matti Virkkunen
I would very much like to hear a reason for the downvote.
Matti Virkkunen
Ok, your right. But that's the architecture at the moment and I can't change it in the near future. :/
benjamin
Saying that synchronous requests should "never" be used is a pretty bold statement. It requires a much better explanation than "they tend to block things". What do they block? How would users bookmark their location if everything in your app is asynchronous?
Lèse majesté
@benjamin: Well, your "architecture" sucks. The only thing I can think of is showing the indicator before the `$.ajax` call, but I doubt that is going to work either. Or using `setTimeout` and friends, but that's even more difficult to implement than just using an asynchronous request.
Matti Virkkunen
@Lèse majesté: I updated my post a little. What I mean by synchronous requests are synchronous XMLHttpRequests. Those have nothing to do with bookmarking or whatnot.
Matti Virkkunen
Ok, that's much more reasonable, but maybe you should include that in your answers (i.e. synchronous `XMLHttpRequests` should never be used).
Lèse majesté
@Lèse majesté: I think my wording is perfectly clear. After all, this post is about XMLHttpRequests.
Matti Virkkunen
Upvote to counter stupidity.
Stefan Valianu
A: 
Lèse majesté
Yeah, the indicator doesn't show up on Google Chrome desktop and on the Android device. I use version 1.4.2 of jQuery.Maybe I play around with jQTouch...
benjamin
@benjamin: Try putting a delay between showing the loading indicator and launching the synchronous XHR.
Lèse majesté
Hi Lèse, it works with the timeout!! Thanks for your great effort!! I can't give you a vote up because I need 15 reputations first! :/
benjamin