Select to view content in your preferred language

Request error unable to load from http://sampleserver6....

7683
20
08-13-2014 04:16 PM
ryannz
by
Deactivated User

Hello everyone, I recently publish my site and it was working fine until today. I got this message:

http://screencast.com/t/BdTyk4X7

Do you know what it is? How can I fix this? When I run the same code locally, it is working fine.

Thanks

Tags (1)
0 Kudos
20 Replies
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   This would be any data that you need in your application that is not provided by one of esris online services already. Say you were wanting to show points on the map for where there is crime in your area. Well it is highly unlikely that esri will have a service with that type of data for your area, but if you did then you could take the data that you have and publish a map service of this data (either using your ArcGIS Server or your AGOL orgazational account).

ryannz
by
Deactivated User

Thanks Robert. In my case, I don't need that level of map yet. I just need a generic map which is pulled using the javascript api. I then projected my drawing on the fly. So actually I don't need to host any data don't I? My only concern now is the use of services on sampleserver. I know it is sampleserver, so there is limitations. Based on the article you shared, the api should be free since it is for non commercial use. Just wondering how I can avoid relying on the sampleserver.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   here is a link to a 10.04 ArcGIS Server that is not a sample server.

http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer

0 Kudos
ryannz
by
Deactivated User

Robert, thanks for the link. It seems to work fine now. The map is loading fine. But when I inspected the code, I got this error. Any idea how to fix this?

XMLHttpRequest cannot load http://tasks.arcgisonline.com/ArcGIS/rest/info?f=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   That goes back to what Owen originally responded with. You may need to use a proxy. So the first thing you have to do is setup a proxy on your hosting service. Go to the esri GitHub Proxy Recource repository and download the flavor of Proxy that your hosting service will allow (asp.net, php, java, etc). Then go through the instructions for setting it up with server urls. Once that is done then you just look at that Link that Owen provided and add those line to specify your proxy url.

ryannz
by
Deactivated User

Thanks Owen for the reply. I am new to arcgis. I saw the sample code and here is how it uses the service:

geometryService = new GeometryService("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");

I am wondering what you mean by using proxy? Does it mean I can't use the url that way? If so could you point me to the right place?

Thanks.

0 Kudos
OwenEarley
Frequent Contributor

The Using the proxy | Guide | ArcGIS API for JavaScript‌ page describes the cases in which you may require a proxy. However, having a proxy configured doesn't change the way that you create and use the geometry service in your code.

I would start by using some debugging tools to determine exactly why the request is failing. Can you post the URL to the published site?

0 Kudos
ryannz
by
Deactivated User

Owen, I inspected element using google chrom and here is the error:

XMLHttpRequest cannot load http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geomet…43794057776715%2C%22spat.... The 'Access-Control-Allow-Origin' header has a value 'http://localhost:6179' that is not equal to the supplied origin. Origin 'http://example.com' is therefore not allowed access.

The message seems to refer to localhost. Where can I change that?

0 Kudos
RiyasDeen
Frequent Contributor

Hi ryan,

Looks like it's a cross site scripting issue. How are you accessing the rest end point, is it xhrRequest?

Have a look at below sample, implementation for button "Good" is one way of doing cross site request, implementation for bad is not.

<!DOCTYPE html>

<html>

  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>

    <title>Simple Map</title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">

    <style>

      html, body, #map {

        height: 100%;

        width: 100%;

        margin: 0;

        padding: 0;

      }

      body {

        background-color: #FFF;

        overflow: hidden;

        font-family: "Trebuchet MS";

      }

    </style>

    <script src="http://js.arcgis.com/3.10/"></script>

    <script>

      var map;

      require(["esri/map", "dojo/dom", "dojo/on", "dojo/io/script", "dojo/request/xhr","dojo/domReady!"], function(Map, dom, On, ioScript, xhr) {

        map = new Map("map", {

          basemap: "topo",

          center: [-122.45, 37.75], // longitude, latitude

          zoom: 13

        });

  On(dom.byId("good"), "click", function(evt) {

  ioScript.get({

  url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer/project...",

  callbackParamName: "callback",

  load: function (data) {

  alert(data.geometries.length);

  },

  error: function (error) {

  alert("asdads");

  }

  });

  });

  On(dom.byId("bad"), "click", function(evt) {

  xhr("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer/project...", {

  handleAs: "json"

  }).then(function(data){

  alert(data.geometries.length);

  }, function(err){

  alert("error");

  });

  });

  });

    </script>

  </head>

  <body>

    <div id="map">

  <button id="good">Good</button>

  <button id="bad">Bad</button>

  </div>

  </body>

</html>

0 Kudos
ryannz
by
Deactivated User

Riyas I tested your code and it seems my problem has gone a way. Here is the jsfiddle I created

http://jsfiddle.net/hkr7cn1x/

I have a few questions. In this line of code:

http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer/project...

I just replace this line with this one:

http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer

This is now working fine. I got another developer develop this for me and here are two lines from his code:

esriConfig.defaults.io.alwaysUseProxy = false;

        geometryService = new GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

Perhaps creating the proxy is way to go. If I don't want to use sampleserver, is there another server that I can use in production environment? Robert, in the previous comment share this link:

http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer

I still got the cross site scripting issue. How can I modify this link?

Thanks a lot.

0 Kudos