3

I'm having some problems to get started using the ESRI JavaSript API. I have a test map service published on my notebook but I can't get it to display. I don't have problems with esri hosted services, just the ones I'm trying to host.

Here is some code:

<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.1" type="text/javascript"></script>
<link href="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
 var myURL = "http://brpnb010/arcgis/rest/services/teste/MapServer";
 // var basemap = new esri.layers.ArcGISTiledMapServiceLayer(basemapURL);
 var myLayer = new esri.layers.ArcGISTiledMapServiceLayer(myURL);
 // map.addLayer(basemap);
 map.addLayer(myLayer);
 dojo.connect(map, "onExtentChange", showExtent);
 }
 function showExtent(extent) {
 var s = "";
 s = "XMin: " + extent.xmin +
 " YMin: " + extent.ymin +
 " XMax: " + extent.xmax +
 " YMax: " + extent.ymax;
 dojo.byId("onExtentChangeInfo").innerHTML = s;
 }
 dojo.addOnLoad(init);
</script>

I'm using Visual Studio to develop, and when the page loads, I get a "Could not load cross domain resources" error.

edit I'm using version 2.1 of the Javascript API. And I'm developing on localhost, which has the brpnb010 name.

Any ideas?

Thanks,

George

Devdatta Tengshe
41.8k36 gold badges147 silver badges267 bronze badges
asked Jan 15, 2011 at 6:43
4
  • So you're running this via localhost? Oh, and what version of the Javascript API are you using? Commented Jan 15, 2011 at 6:47
  • Hey Michael. I've edited the question to include answers to your questions :D Commented Jan 15, 2011 at 19:32
  • 2
    What does Fiddler show? fiddler2.com/fiddler2 Commented Jan 15, 2011 at 20:18
  • I have the same problem with version 2.6. When I try to use dojo.require("esri.geometry.Polygon"); I get an error saying: uncaught exception: Could not load cross-domain resources: esri.geometry.tasks.Polygon Commented Jul 16, 2016 at 4:36

3 Answers 3

3

Post more code. Could not load cross domain resource either means you spelled a dojo require wrong or you are accessing JavaScript files via xhr that have different domain names. Use firefox and firebug and look at the net and console tabs and post what errors you are getting there

Also what's up with the proxy. You shouldn't need that on localhost dev.

I also don't think you need to require .geometry or .layer

this works:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
 <title>Test Page</title>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.1" type="text/javascript"></script>
<link href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.1/js/dojo/dijit/themes/claro/claro.css" rel="stylesheet" type="text/css" >
<script type="text/javascript">
 dojo.require("esri.map");
 //dojo.require("esri.geometry");
 //dojo.require("esri.layers");
 var map;
 function init() {
 map = new esri.Map("mapDiv");
 // var basemapURL = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
 var myURL = "http://mapserv.utah.gov/ArcGIS/rest/services/UtahBaseMap-Topo/MapServer";
 // var basemap = new esri.layers.ArcGISTiledMapServiceLayer(basemapURL);
 var myLayer = new esri.layers.ArcGISTiledMapServiceLayer(myURL);
 // map.addLayer(basemap);
 map.addLayer(myLayer);
 dojo.connect(map, "onExtentChange", showExtent);
 }
 function showExtent(extent) {
 var s = "";
 s = "XMin: " + extent.xmin +
 " YMin: " + extent.ymin +
 " XMax: " + extent.xmax +
 " YMax: " + extent.ymax;
 dojo.byId("onExtentChangeInfo").innerHTML = s;
 }
 dojo.addOnLoad(init);
</script>
</head>
<body class="claro">
<div id="mapDiv"></div>
<div id="onExtentChangeInfo"></div>
</body>
</html>
answered Jan 16, 2011 at 5:25
4
  • When developing with OpenLayers you need a proxy to show WFS services (I know it's not case, just tried a lot of different things to see if it worked). I'll check out fiddler and firebug and i'll post some info here. Commented Jan 16, 2011 at 14:36
  • i would start out removing the proxy and the dojo.require's that are not necessary and see if it works. I'm thinking you're getting the could not load xd resource because of your requires. Commented Jan 17, 2011 at 1:04
  • @George, have you got this working yet? Commented Feb 16, 2011 at 18:58
  • yea I got it working. Wrong dojo name. :P Commented Mar 7, 2011 at 19:49
1

I think the problem is in the API requires at the top, they keep changing at each version. Try dojo.require("esri.tasks.geometry") instead of "esri.geometry" at version AGS JS API 2.1. Also, I don't see a need for "esri.layers" to simply add a layer. This would need to be further qualified if you were going to work with a layer object (such as GraphicsLayer, or FeatureLayer). Just make sure you are using the correct object(s) per your DOJO/JS API version.

answered Jan 26, 2011 at 21:14
1

Is your local service really a Tiled service? If not, you should be using an esri.layers.ArcGISDynamicMapServiceLayer(myURL);

answered Jun 8, 2011 at 15:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.