Select to view content in your preferred language

Cross domain request....

947
3
07-24-2010 08:47 PM
GISAdmin1
Regular Contributor
I would like to retrieve the JSON results of a REST identify request using something like a xmlhttprequest.  The problem is, my ArcGIS Server is not on the same domain, so, my request will fail (cross domain).  Does anyone have any suggestions on how to grab the JSON from a REST call and use it via Javascript?

Thanks in advance,

M
0 Kudos
3 Replies
RahulRavikumar
Emerging Contributor
This has already been baked into the JavaScript API. You can use an esri namespace method called "esri.request(...)"

The full API reference documentation for the method is at : http://http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/namespace_esri.htm#request

esri.request({
  url:"http://..../rest/services/USA/MapServer", 
  content: {
    param1: "value1",
    param2: "value2",
    param3: "value3"
  },
  callbackParamName:"callback",
  load:function(response, io) {
    ...
  }, 
  error:esriConfig.defaults.io.errorHandler
});
0 Kudos
__Rich_
Deactivated User
(I'm not sure Rahul's understood the issue you're facing?)

You'll need to satisfy 'same origin policy', you could achieve this by employing a proxy, e.g. the 'stock' proxy page should be be all you require for your particular needs.

HTH 🙂
0 Kudos
DavidHollema
Deactivated User
When you say this has been "baked into the JavaScript API"...I'm curious what that means?  How are cross-domain requests performed without a proxy page?  Is it using jsonp and script tag injection?

This has already been baked into the JavaScript API. You can use an esri namespace method called "esri.request(...)"

The full API reference documentation for the method is at : http://http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/namespace_esri.htm#request

esri.request({
  url:"http://..../rest/services/USA/MapServer", 
  content: {
    param1: "value1",
    param2: "value2",
    param3: "value3"
  },
  callbackParamName:"callback",
  load:function(response, io) {
    ...
  }, 
  error:esriConfig.defaults.io.errorHandler
});
0 Kudos