javascript 使用 D3 从休息服务中获取数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32236660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get data from rest service using D3
提问by kennechu
I have a working web service at http://localhost/RestService/GetTransactionByStatus/1. When I run that URL on my browser I'm getting the correct JSON-formatted response:
我在http://localhost/RestService/GetTransactionByStatus/1有一个可用的 Web 服务。当我在浏览器上运行该 URL 时,我得到了正确的 JSON 格式的响应:
{
"transactionConcil" : "TRANSACTIONS OK",
"numTransactionConcil" : 0,
"transactionNoConcil" : "TRANSACTIONS NOT OK",
"numTransactionNoConcil" : 0
}
How can I manage this REST service in order to present the correct data in my browser using a web service? The data is going to be managed dynamically so the information that is going to be displayed depends on the ID (last param in the URL).
如何管理此 REST 服务,以便使用 Web 服务在浏览器中显示正确的数据?数据将被动态管理,因此将要显示的信息取决于 ID(URL 中的最后一个参数)。
回答by schrieveslaach
Look at the documentation. Here is an example:
查看文档。下面是一个例子:
d3.json('http://localhost/RestService/GetTransactionByStatus/' + id, function(data) {
console.log(data.transactionConcil);
});
回答by Krisrs1128
As of d3 v5, this has become
从 d3 v5 开始,这已成为
d3.json('http://localhost/RestService/GetTransactionByStatus/' + id)
.then(function(data) {
console.log(data.transactionConcil);
});
回答by Harry_pb
Update 2019:
2019 年更新:
For any host - localhost
or some server
, you can directly get data by just mentioning rest api path
, so that your code can be used on any server
对于任何主机localhost
或某些主机server
,您只需提及即可直接获取数据rest api path
,以便您的代码可用于任何主机。server
d3.json("/RestService/GetTransactionByStatus/" + id, function(error, data) {
console.log(data);
});