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;
});
Best Answer
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:
Full example here.