Firefox Firebug Error: XHR Cancelled

7382
9
12-12-2012 07:48 AM
Dan
by
Occasional Contributor
Javascript API 10.1

I created a layer and a renderer.

After I add the layer to the map . . .

map.addLayer(myLayer);

. . . I generate the renderer:

generateRenderer.execute(params, ftnApplyRenderer, ftnErrorHandler);

Everything works fine, but I get an 'xhr cancelled' error in Firebug (Firefox 17.0) in the function below when refresh() is called on the layer:

function ftnApplyRenderer(renderer) {
'use strict';
myLayer.setRenderer(renderer);
myLayer.refresh();
}

If I comment out the refresh() part, the error goes away, but then the layer doesn't render.

If I clear the error console and run the above function again, the error does not occur. It seems that when the layer is added, dojo is still doing something that gets cancelled when the refresh() method is called.

Even though the application still works fine, how can I avoid this error?

Thanks.

-Dan
0 Kudos
9 Replies
KeG
by
New Contributor II
I am seeing similar. When i have refresh i get those errors but when i don't it seems like the layer is a click behind. I'm using a feature layer with a tooltip on hover and i'm hiding and showing the layer and then trying to force a refresh.
I don't have an answer, sorry, i think it is related to the timing of when the layer is interacted with.
0 Kudos
Dan
by
Occasional Contributor
As suspected, this is a timing issue . . .

If I put refresh() inside a timeout, the error goes away:

setTimeout('myLayer.refresh();', 1000);

This, however, is not a real solution.

I've been looking into the dojo deferred examples, but . . . I'm totally new to JSAPI and dojo, and not sure if that is the right way to go.

Help appreciated.

Thanks.

-Dan
0 Kudos
Dan
by
Occasional Contributor
For a live example of a similar error, please visit the ESRI JSAPI sample at the link below:

http://help.arcgis.com/en/webapi/javascript/arcgis/samples/renderer_generate_renderer/index.html

(NOTE: The error is intermittent so you may need to load the page a few times and select from the drop-down list a few times before the error presents itself.)

Click image below to see the 'Unable to draw graphic (null)' error:

[ATTACH=CONFIG]19998[/ATTACH]
0 Kudos
SimonUyttendaele
New Contributor III
This error message (xhr cancelled) is a "feature" from Dojo :

http://dojotoolkit.org/reference-guide/1.9/dojo/xhrGet.html

If you cancel the XHR, the error callback will be triggered, think about it if you handle errors with a �??try again�?� mechanism, since you may reschedule a canceled request


When you move the map around, or call a refresh, sometimes, pending requests are cancelled by the API because they are already outdated.
Thus, Dojo triggers the "onError" event.

To my opinion, this should be caught by the API and not forwarded to the layer's "onError" callback...
SimonUyttendaele
New Contributor III
A bit late but it may be useful for other people.
Here is a solution to get rid of "xhr cancelled" messages :

 if( typeof esri.layers.Layer.prototype._errorHandler == 'function' )
 {
  esri.layers.Layer.prototype._errorHandler = function(error)
  {
   if( error && error.message && error.message == "xhr cancelled" )
    return;
   this.onError(error);
  }
  
  dojo.config.deferredOnError = function(e){}
  dojo._ioSetArgs2 = dojo._ioSetArgs;
  dojo._ioSetArgs = function(_14,_15,_16,_17)
  {
   return dojo._ioSetArgs2(_14,_15,_16,function(a,b){return a;});
  }
 }


Regards
FC_Basson
MVP Regular Contributor

Hi Simon Uyttendaele

Can you advise where to add this code?

0 Kudos
simonuyttendaele1
New Contributor

This is a "hack" in the API, so I cannot guarantee that this is still compatible with latest version of the API.

You should place this in your javascript as soon as possible after once the esri.layers package is loaded.

Regards,

FC_Basson
MVP Regular Contributor

Thanks Simon, it works.  I'm still using the 3.12 API version.  Inserted it at the start of my "require" first function.

0 Kudos
Rolandvan_Zoest
New Contributor III

Thanks Simon,

3 years later ... this still works !

0 Kudos