L.esri.request

Generic methods to make GET and POST requests to ArcGIS Online and ArcGIS Enterprise. These methods will handle serializing the input parameters and parsing of the response, making them available in a callback function via a response and error property similar to Node.js.

GET requests will be made with XMLHttpRequest (via CORS) if the browser supports it and will fallback to JSONP. POST requests will always be made with XMLHttpRequest (via CORS). The ArcGIS Resource Proxy or something similar must be configured to support cross domain requests via L.esri.Service if CORS cannot be leveraged.

If you are using a version of ArcGIS Server older than 10.1, CORS is not enabled by default but can be configured using the documentation available at http://enable-cors.org/. If you cannot enable CORS, the following line of code will force all requests to be made using JSONP instead.

L.esri.Support.cors = false;

L.esri.request(url, params, callback);

Executes a GET or POST via XMLHttpRequest or JSONP request depending on the capabilities of the browser and the length of the request. GET is used when the browser supports CORS and the request url is less then 2000 characters. POST is used when the browser supports CORS and the request exceeds 2000 characters. JSONP is used when the request is less then 2000 characters and the browser does not support CORS.

Params

Param Value Description
url String The URL to request.
params Object The parameters to send as a query string.
callback Function Function to run when the request completes, will be passed an error and response.
context Object Optional function context for the callback.

Example

L.esri.request('https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Heritage_Trees_Portland/FeatureServer/0', {}, function(error, response){
  if(error){
    console.log(error);
  } else {
    console.log(response.name);
  }
});

L.esri.get(url, params, callback)

Execute a GET request via `XMLHttpRequest' (via CORS) or JSON depending on what is available in the browser.

Note: ArcGIS Server before 10.1 does not have CORS support enabled by default. You can either enable CORS on your server or tell Esri Leaflet to always make JSONP requests with L.esri.get = L.esri.Request.get.JSONP; After you load Esri leaflet, but before calling your own scripts.

Params

Param Value Description
url String The URL to request.
params Object The parameters to send as a query string.
callback Function Function to run when the request completes, will be passed error and response.
context Object Optional function context for the callback.

Example

L.esri.get('https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Heritage_Trees_Portland/FeatureServer/0', {}, function(error, response){
  if(error){
    console.log(error);
  } else {
    console.log(response.name);
  }
});

L.esri.post(url, params, callback)

Execute a POST request via `XMLHttpRequest' (via CORS).

This request is made via XMLHttpRequest which cannot make cross domain requests in IE 8 and 9. Esri Leaflet supports both the ArcGIS API for JavaScript proxy and the ArcGIS Resource Proxy which can be hosted on your server and used with the L.esri.Service classes to work around this issue.

Param Value Description
url String The URL to request.
params Object The parameters to send as a query string.
callback Function Function to run when the request completes, will be passed error and response.
context Object Optional function context for the callback.

Example

L.esri.post('https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Heritage_Trees_Portland/FeatureServer/0', {}, function(error, response){
  if(error){
    console.log(error);
  } else {
    console.log(response.name);
  }
});

Edit this page on GitHub