Get data from rest service using D3

14,643

Solution 1

Look at the documentation. Here is an example:

d3.json('http://localhost/RestService/GetTransactionByStatus/' + id, function(data) {
    console.log(data.transactionConcil);
});

Solution 2

As of d3 v5, this has become

    d3.json('http://localhost/RestService/GetTransactionByStatus/' + id)
      .then(function(data) {
        console.log(data.transactionConcil);
       });

Solution 3

Update 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

d3.json("/RestService/GetTransactionByStatus/" + id, function(error, data) {
            console.log(data);
});
Share:
14,643
kennechu
Author by

kennechu

Updated on July 28, 2022

Comments

  • kennechu
    kennechu almost 2 years

    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:

    {
        "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).