Issue Upgrading to version 3.0

5499
18
06-14-2012 05:13 AM
AdamConner
New Contributor
I am attempting to upgrade to version 3.0 of the API, and I have started getting errors.  The error I get is seen in the sample http://help.arcgis.com/en/webapi/javascript/arcgis/demos/widget/widget_basemapManual.html  I imagine this is a bug since the sample is broken as well.  Has anyone else seen or resolved this issue?

Thanks,
Adam Conner
City of Philadelphia
0 Kudos
18 Replies
JeffPace
MVP Alum
I am attempting to upgrade to version 3.0 of the API, and I have started getting errors.  The error I get is seen in the sample http://help.arcgis.com/en/webapi/javascript/arcgis/demos/widget/widget_basemapManual.html  I imagine this is a bug since the sample is broken as well.  Has anyone else seen or resolved this issue?

Thanks,
Adam Conner
City of Philadelphia


I get the same error, both on the sample and on my own app.

Whenever a layer is loaded it tries to access
http://sampleserver1.arcgisonline.com/ArcGIS/rest/info?f=json
or in my case also
http://services.arcgisonline.com/ArcGIS/rest/info?f=json (world basemap)
and
http://www.mymanatee.org/arcgis/rest/info?f=json (local services)

These return valid json (200 0k http code) but for some reason throw an error in the app
the error is (on the sample)

XMLHttpRequest cannot load http://sampleserver1.arcgisonline.com/ArcGIS/rest/info?f=json. Origin http://help.arcgis.com is not allowed by Access-Control-Allow-Origin.

and on my local development site
XMLHttpRequest cannot load http://www.mymanatee.org/arcgis/rest/info?f=json. Origin http://jpgisdev.intranet is not allowed by Access-Control-Allow-Origin.

Its seems like arcgis server is not properly returning the Access-Control-Allow-Origin "*" headers in the response.
0 Kudos
AdamConner
New Contributor
I was able to get rid of the cross origin error by adding the allow cross origin header.  I used the instructions here: http://enable-cors.org/  I still get the "Uncaught TypeError: Cannot read property 'className' of null "  error even after this is fixed, this is the issue I am considering to be a bug until I hear otherwise.
0 Kudos
JeffPace
MVP Alum
I was able to get rid of the cross origin error by adding the allow cross origin header.  I used the instructions here: http://enable-cors.org/  I still get the "Uncaught TypeError: Cannot read property 'className' of null "  error even after this is fixed, this is the issue I am considering to be a bug until I hear otherwise.


Where did you add it?
0 Kudos
ReneRubalcava
Frequent Contributor
Good, I assumed it was because I was running from a localhost, but then I pushed to a server and got same errors. In my case, it does not break my app, just a little annoying error. I've been running 3.0 through it's paces since yesterday and think I'm finally ready to update my apps.
0 Kudos
KellyHutchins
Esri Frequent Contributor
This error can be ignored - here's a blurb from the help on this error:


Automatic detection of CORS support. This is done by attempting to access the /<instance-name>/rest/info endpoint of any ArcGIS server instance used in an ArcGIS API for JavaScript application. For servers that do not support CORS, this request will fail and an error will be logged to the browser's developer console. This can be observed in most of the API's samples as the majority of the servers used do not support CORS. This error can safely be ignored. There are cases where the API will not send a request to /<instance-name>/rest/info and are as follows:
The browser does not support CORS
The Server is already listed in esri.config.defaults.io.corsEnabledServers
esri.config.defaults.io.corsDetection is false
JSON is used instead of JSONP in the following cases:
The resource being fetched is on the same domain as the application
The resource being fetched is on a server that supports CORS

To read the blurb in context see the API reference for esri.request
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/namespace_esri.htm
0 Kudos
AdamConner
New Contributor
This error can be ignored - here's a blurb from the help on this error:


Automatic detection of CORS support. This is done by attempting to access the /<instance-name>/rest/info endpoint of any ArcGIS server instance used in an ArcGIS API for JavaScript application. For servers that do not support CORS, this request will fail and an error will be logged to the browser's developer console. This can be observed in most of the API's samples as the majority of the servers used do not support CORS. This error can safely be ignored. There are cases where the API will not send a request to /<instance-name>/rest/info and are as follows:
The browser does not support CORS
The Server is already listed in esri.config.defaults.io.corsEnabledServers
esri.config.defaults.io.corsDetection is false
JSON is used instead of JSONP in the following cases:
The resource being fetched is on the same domain as the application
The resource being fetched is on a server that supports CORS

To read the blurb in context see the API reference for esri.request
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/namespace_esri.htm


Kelly,
  the CORS issue I am fine with ignoring, the fact that the sample code for creating a basemap gallery breaks is not related to CORS.  The link to the sample is here http://help.arcgis.com/en/webapi/javascript/arcgis/demos/widget/widget_basemapManual.html
on line 83

var basemapGallery = new esri.dijit.BasemapGallery({
         showArcGISBasemaps:false,
         basemaps:basemaps,
         map:map
        },"basemapGallery");
        basemapGallery.startup();


that call causes an uncaught error: "Uncaught TypeError: Cannot read property 'className' of null "

this is the issue that still exists and cannot be ignored.
0 Kudos
RobertWinterbottom
Occasional Contributor
Im having a similar issue.  I upgraded my map to 3.0 this morning and at first it would not work at all until I moved some variables around.  Got it too work temporarily, went to lunch, and when I got back it was no longer working.   The error is "Type Error: cannot call method 'setRenderer' of null".  It is referring to where I call map.graphics.setRenderer(renderer), I had it working on 2.8 and even on 3.0 for a little but all of sudden the map stopped working.  Also getting "Uncaught Error: esri is not defined" when I try to create an extent object to be used as my initial extent.
0 Kudos
KellyHutchins
Esri Frequent Contributor
Ok this issue looks like a bug but you can workaround it by adding the following before creating the basemap gallery

esri.dijit.BasemapGallery.prototype._markSelected = function (basemap) {
  if (basemap) {
    // unselect all basemap gallery items
    dojo.forEach(dojo.query(".esriBasemapGallerySelectedNode",
this.domNode), function (node) {
      dojo.removeClass(node, "esriBasemapGallerySelectedNode");
    });
    // select current basemap gallery item
    var basemapNode = dojo.byId("galleryNode_" + basemap.id);
    if (basemapNode) {
      dojo.addClass(basemapNode, "esriBasemapGallerySelectedNode");
    }
  }
}



Kelly,
  the CORS issue I am fine with ignoring, the fact that the sample code for creating a basemap gallery breaks is not related to CORS.  The link to the sample is here http://help.arcgis.com/en/webapi/javascript/arcgis/demos/widget/widget_basemapManual.html
on line 83

var basemapGallery = new esri.dijit.BasemapGallery({
         showArcGISBasemaps:false,
         basemaps:basemaps,
         map:map
        },"basemapGallery");
        basemapGallery.startup();


that call causes an uncaught error: "Uncaught TypeError: Cannot read property 'className' of null "

this is the issue that still exists and cannot be ignored.
0 Kudos
KellyHutchins
Esri Frequent Contributor
Robert,

Check out the 'Migrating to 3.0' doc for some tips on upgrading your app:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/migration_30.htm

If that doesn't help can you provide a code snippet that shows the problem?


Im having a similar issue.  I upgraded my map to 3.0 this morning and at first it would not work at all until I moved some variables around.  Got it too work temporarily, went to lunch, and when I got back it was no longer working.   The error is "Type Error: cannot call method 'setRenderer' of null".  It is referring to where I call map.graphics.setRenderer(renderer), I had it working on 2.8 and even on 3.0 for a little but all of sudden the map stopped working.  Also getting "Uncaught Error: esri is not defined" when I try to create an extent object to be used as my initial extent.
0 Kudos