[OpenLayers-Users] ajax onfailure does not decrease requests counter

Duarte Carreira DCarreira at edia.pt
Mon May 14 04:48:58 EDT 2007


Christopher,

My function for onComplete tests for activeRequestCount == 0 and if it
is  then hides the progress animation. Now, when an ajax request fails
the counter fails the test.

This is the code for onComplete and onCreate:

OpenLayers.Ajax.Responders.register({
  onCreate: function() {
    if($('ocupado') && OpenLayers.Ajax.activeRequestCount > 0) {
      $('ocupado').style.display = 'block';
      $('estado').innerHTML = '#: ' +
OpenLayers.Ajax.activeRequestCount;
    }
				
  },
  onComplete: function() {
    if($('ocupado') && OpenLayers.Ajax.activeRequestCount == 0) {
      $('ocupado').style.display = 'none';
      $('estado').innerHTML = '#: ' +
OpenLayers.Ajax.activeRequestCount;
    }
  }
}); 

Reading your message I got the feeling that maybe my onComplete should
decrease the counter? But it's working as long as there aren't any
failures. So the counter is decreasing somewhere else.

To work around this issue I've worked on the loadURL onFailure function.
Here I decrease activeRequestCount, and hide the animation if it reaches
0. 
The application is now a bit extensive so it's not a really good test
scenario. For the same reason, I cannot guarantee something weird other
than OL is not going on. If I get the opportunity I will create a test
scenario and report back on it.

As for an onLoaded event for map or layer objects it's a pity we don't
get one... but life goes on!

Thanks for your help.
Duarte


-----Mensagem original-----
De: Christopher Schmidt [mailto:crschmidt at metacarta.com] 
Enviada: domingo, 13 de Maio de 2007 17:35
Para: Duarte Carreira
Cc: users at openlayers.org
Assunto: Re: [OpenLayers-Users] ajax onfailure does not decrease
requests counter

On Sun, May 13, 2007 at 04:54:06PM +0100, Duarte Carreira wrote:
> 
> Hi all.
> 
> I'm using OL2.3 and I'm using loadURL as the ajax mechanism.
> 
> I use OpenLayers.Ajax.Responders.register to show and hide a small
animated icon to show when client-server communication is going on. This
works fine until there's a failed request.
> 
> As far as I can see, when an ajax request fails OL does not update
OpenLayers.Ajax.activeRequestCount, so my function does not hide the
animated icon.

Huh. That's interesting, because I'm sure that onComplete is called
(when registered as an option to Ajax.Request) on failures...  

> I feel the counter should be decreased every time a request
terminates, even if it failed.

Agreed.

> Also, I don't know if the responder onComplete gets fired when a
request fails.

I'm under the impression that it does, but if it doesn't, patches to
that part of the code to make it do the right thing are welcome. Feel
free to open a ticket on the topic.  

> As long as I'm on the subject I would like to ask if there's a way to
know when tiles have finished loading on a map or layer? I have searched
the list for this and did not find a solution. But OL is evolving so
fast I'm hoping maybe there is.

I think WMS.Untiled has this ability, but other layers don't -- for the
same types of problems you're now running into with Ajax :)

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list