从远程服务器请求数据

尝试一下在线预览

这个示例展示了如何使用一些基本选项从远程服务器检索数据。

首先要做的是为请求定义选项。

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:
  // ?f=json
  query: {
    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"
};

响应对象将由属性 datarequestOptionsurl 组成。您可以根据需要处理响应。

1
2
3
4
5
6
// The URL is the first argument, you can also pass the options as the second argument.
geosceneRequest(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;
});

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.