d3.json调用总是获取空数据 [英] d3.json call always gets null data

查看:335
本文介绍了d3.json调用总是获取空数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我通过浏览器拨打此服务器: http:// localhost: 8080 / api / items / number / all.json 或从curl(curl -G http:// localhost:8080 / api / items / number / all.json )我回到以下json:

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
}

$ b b

但是,当我使用d3.json调用:

However when I use d3.json call:

d3.json("http://localhost:8080/api/items/number/all.json", function(jsondata){
            console.log(jsondata);
});

console.log的输出为空。

the output from console.log is null.

如果改为使用http调用,我将json保存在文件(fileWithData.json)中并执行:

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?

推荐答案

在d3-js Goole组的帮助下解决。
问题是,加载json的页面不是从localhost:8080提供的,因此,存在跨域限制。我刚刚在同一个应用程序中部署了该文件。
如果必须进行跨域调用,组建议使用jasonp和特别和CORS(
http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-与跨源起源资源共享/

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/ )

这篇关于d3.json调用总是获取空数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆