Replacement setting for L.esri.get = L.esri.Request.get.JSONP

3563
1
Jump to solution
09-15-2015 12:40 PM
Labels (1)
ChadHutcherson
New Contributor

Can you tell me what value to change in v2 beta 5 that will cause esri leaflet to default to JSONP instead of CORS? 

 

Our SSO setup returns a '302 found' when using the default CORS requests.  If I make the change below, everything works fine.

 

https://github.com/Esri/esri-leaflet/blob/master/src/Support.js#L1

export var cors = ((window.XMLHttpRequest && 'withCredentials' in new window.XMLHttpRequest()));

 

export var cors = false;

 

The docs show that the old way to turn off default CORS is:

If you cannot or do not want to enable CORS on your server the following code will make all requests utilize JSONP.

L.esri.get = L.esri.Request.get.JSONP;

 

But release notes for Beta 2 say:

  • L.esri.Request has been removed. Please use L.esri.get, L.esri.get.CORS, L.esri.get.JSONP,L.esri.post or L.esri.request directly.

 

What is the new way to do this in beta 2?

0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Frequent Contributor

Esri Leaflet only falls back onto JSONP when POSTing from a client browser that doesn't support CORS.  if you'd like to trick our plugin into thinking that the end users browser doesn't support CORS, you can call...

L.esri.Support.cors = false;

Afterward, when calling L.esri.request(), JSONP will be used if its necessary to POST.

// to send a single JSONP ajax request
L.esri.request('http://sampleserver6.arcgisonline.com/arcgis/rest/services/', {
  fakeParam: 'value that will push the request length past 2000 characters'
}, function (error, response) {
  if (error) {
    console.log(error)
  } else {
    console.log(response)
  }
})

If you need to POST across domains, please remember that it will be necessary to invoke a proxy.

we'll be updating the API reference soon, so i'll make sure the new information pertaining to L.esri.request() is as clear as possible.

View solution in original post

0 Kudos
1 Reply
JohnGravois
Frequent Contributor

Esri Leaflet only falls back onto JSONP when POSTing from a client browser that doesn't support CORS.  if you'd like to trick our plugin into thinking that the end users browser doesn't support CORS, you can call...

L.esri.Support.cors = false;

Afterward, when calling L.esri.request(), JSONP will be used if its necessary to POST.

// to send a single JSONP ajax request
L.esri.request('http://sampleserver6.arcgisonline.com/arcgis/rest/services/', {
  fakeParam: 'value that will push the request length past 2000 characters'
}, function (error, response) {
  if (error) {
    console.log(error)
  } else {
    console.log(response)
  }
})

If you need to POST across domains, please remember that it will be necessary to invoke a proxy.

we'll be updating the API reference soon, so i'll make sure the new information pertaining to L.esri.request() is as clear as possible.

0 Kudos