I do understand how the proxy helps in transferring the XMLHttpRequest between the ArcServer and the Server (IIS/Apache) but where I am confused is that the first time the Html Doc loads, doesn't the Server need to request the ArcServer then as well. How does that request complete without the proxy?

I mean the first time the page loads it does not need that proxy and still the map is loaded in the Map container. But later if we send a XMLHttpRequest to the Geoprocessing Tool, the response from the ArcServer can only be received by the Server if we have setup the proxy, right?

So how does it happen the first time and not the second time?


1 Answer 1


The JS API makes extensive use of JSONP, and this is how service metadata is retrieved. Once the JS API knows about a map service, it can insert tags to display map tiles or images from dynamic map services.

You're correct that there are certain cases where a proxy is required. You can read up about them in the "Using a Proxy" section of the Inside esri.request help topic.

Edit: Providing more info below about how esri.Map, map services and geoprocessing services work.

Accessing map services from the ArcGIS Server REST API does not require a proxy or CORS. This is because map service info can be retrieved via JSONP, which circumvents browsers' same origin policy. Once a map service is created and added to a map, the map tiles (or map images if the service is not cached) are inserted into the page by creating img tags. You can see this if you look at a page's DOM via Firefox or Chrome's developer tools. Since img tags (as well as script and link tags) are not subject to same origin, this works without a proxy or CORS.

For GP services, things are a little different. GP services usually take a number of inputs, and the request (the URL specifying input parameters) to a GP service is usually quite long. Because certain browsers impose a limit on URL length, to ensure cross browser compatibility, the JS API will switch to doing a POST rather than a GET when a URL is longer than ~2k characters. Cross domain POSTs are prohibited by same origin, and this is why a proxy (or CORS) is required. If you are using a GP service that accepts a small number of inputs, and only accepts a point (lines and polygons quickly increase URL length because every vertex is specified part of the request), it is possible possible to use GP service without a proxy or CORS. The key thing to remember is that if a URL is less than ~2k characters, and the request can be completed with a GET request, a proxy/CORS are not required. If the request must be done via a POST (an edit operation, for instance), and the service you're using is not on the same domain as your application, a proxy or CORS is required.

  • Thanks @Derek, but my question still remains unanswered. I do know how to setup a proxy or setup CORS but what I am not able to understand, is How come, without setting up the proxy or CORS, the map from sampleserver loads in the map container as the document loads but when I am trying to accesses the geoprocessing tool from the same sampleserver i need proxy?
    – Sam007
    Commented Sep 11, 2012 at 16:50
  • @Sam007 added more info, please see my answer above. Commented Sep 11, 2012 at 21:24
  • Thanks a lot @Derek. I was finally able to understand. Really explained well in detail. The img tag was especially the bullseye. I have seen the map represented as tiles, but never occured to me that they are being transferred as img, which is common sense. Thanks that was a great explaination
    – Sam007
    Commented Sep 11, 2012 at 21:40
  • @Sam007 you're welcome and my pleasure, glad I could help :) Commented Sep 11, 2012 at 22:16
  • Derek, THANK YOU! For posting so many helpful comments here, and even more so for posting working examples on JSFiddle. Postings from both you and Kelly have been absolutely vital in my learning of Javascript and the ESRI API. Just wanted to say thank you.
    – user16713
    Commented Apr 1, 2013 at 13:32

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.