Select to view content in your preferred language

Esri Request and callbackParamName

1106
1
12-13-2017 03:25 PM
JamesS1
Regular Contributor

I have a url that returns a callback (JSONP):

http://warrencountyny.gov/rp/section.php?r=text&pk=302.15-12-24&town=520500

What is the proper way to use esriRequest with JSONP?

I have:

esriRequest(url, { callbackParamName: 'callback' }).then(function (result) {
   console.log(result);
}).otherwise(function (err) { console.log(err); });

This fails with an expected JSON error.

If I do:

esriRequest(url, { responseType:'jsonp', callbackParamName: 'callback' }).then(function (result) {
   console.log(result);
}).otherwise(function (err) { console.log(err); });

It returns the data (result.data) as a string:

callback({
   "file": "Glens Falls/Glens Falls_302.15.pdf",
   "size": "372.72 kB"
});

If I do this inside, I can get the "file":

esriRequest(url, { responseType: 'jsonp', callbackParamName: 'callback' }).then(function (response) {

   var jsonp = response.data;

   var f = new Function('callback', jsonp);
   f(function (json) {
      console.log(json.file);
   });

}).otherwise(function (err) { console.log(err); });

Is this the right way to do this, or am I missing something? Any thoughts are appreciated.

0 Kudos
1 Reply
JamesS1
Regular Contributor

Since it is working as I have it in the last example, I'm going to leave it as it is for now.