Why is esriRequest not working?

4505
10
Jump to solution
05-23-2019 05:26 AM
JustinBridwell2
Occasional Contributor II

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;      
});
0 Kudos
10 Replies
RobertScheitlin__GISP
MVP Emeritus

Justin,

  Most likely you are trying to access the results before they have returned then. You have to understand the nature of a async call.