Reputation: 593
If I make this call to the server from a browser:
http://localhost:8080/api/items/number/all.json
Or from curl:
curl -G http://localhost:8080/api/items/number/all.json
I get back the following json:
{
"language": null,
"number": 10,
"queryId": 0,
"from": null,
"to": null,
"percentage": 33,
"dataInfoSet": null
}
However when I use d3.json
call:
d3.json("http://localhost:8080/api/items/number/all.json", function(jsondata) {
console.log(jsondata);
});
The output from console.log
is null
.
If instead the http call, I save the json in a file (fileWithData.json) and do:
d3.json("fileWithData.json", function(jsondata) {
console.log(jsondata);
});
Everything works as expected. Does anyone know what might be the problem?
Upvotes: 3
Views: 5087
Reputation: 593
Solved with the help of d3-js Goole group. The problem was that the page loading the json was not being served from localhost:8080, thus, there were cross domain restrictions. I just deployed the file within the same application. In case cross domain calls have to be made, the group suggested the use of jasonp and specially and CORS ( http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/ )
Upvotes: 3