This sample shows how retrieve data from a remote server with some basic options.
The first thing you want to do is define the options for your request.
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
var options = {
// These properties will be appended to the request URL in the following format:// <url>?f=jsonquery: {
f: "json" },
// Determine the format you want to read the response as.// Default type is 'json'. Other values are 'xml', 'text', 'blob', 'arraybuffer', 'document'.responseType: "json"};
The response object will consist of the properties data, requestOptions and url. You can handle the response as needed.
Use dark colors for code blocksCopy
1
2
3
4
5
6
// The URL is the first argument, you can also pass the options as the second argument.esriRequest(url, options).then(function(response) {
// In this case, we simply print out the response to the page.var responseJSON = JSON.stringify(response, null, 2);
resultsDiv.innerHTML = responseJSON;
});