0

I am trying to use esri/request to pull in some data from an API. I am have two weird problems. First, when I try to run this, it doesn't complete and throws the following error in the browser console: "Uncaught TypeError: Cannot read property 'trim' of undefined". I am not using trim() anywhere and am not sure why this error is being thrown (specifically on the line where I make my esriRequest). Second, if I try to test this in the browser by pasting in the function to the console, it says that esriRequest is not defined. I have checked the order of my required list and functions several times and they look like they are in the proper order. Am I missing something here?

require([
    "esri/map",
    "esri/basemaps",
    "esri/dijit/BasemapToggle",
    "esri/layers/ArcGISDynamicMapServiceLayer",
    "esri/tasks/ImageServiceIdentifyTask",
    "esri/tasks/ImageServiceIdentifyParameters",
    "esri/layers/WebTiledLayer",
    "esri/dijit/Search",
    "esri/config",
    "esri/request",
    "dojo/json",
    "dojo/promise/all", 
    "dojo/domReady!"], function(
        Map, 
        esriBasemaps, 
        BasemapToggle, 
        ArcGISDynamicMapServiceLayer, 
        ImageServiceIdentifyTask, 
        ImageServiceIdentifyParameters, 
        WebTiledLayer, 
        Search, 
        esriConfig, 
        esriRequest, 
        JSON, 
        all) {

        .....
       var url = "https://earthquake.usgs.gov/ws/designmaps/asce7-16.json?latitude=18&longitude=-66&riskCategory=I&siteClass=D&title=Default";
      esriRequest(url, {
        responseType: "json"
      }).then(function(response){
        // The requested data
        var seis_data = response.data;
      });
1

There's an issue with the format of inputs for esriRequest. You must pass an object as the first parameter, with your url as the value in the "url" property of that object:

esriRequest({
    url: url
  }).then(...);

Full example here.

  • 1
    That was indeed the main issue. Thanks for making the JS Bin example; that was very helpful! Also, thanks for adding the esriConfig with CORS stuff. I immediately ran into that issue when request started working properly and that resolved it. – gwydion93 May 28 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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