Alb*_*ban -1 php json get download d3.js
我使用d3.js和CodeIgniter,当我运行此代码时,当我使用d3.json获取json数据时,我遇到了问题:
var url = "http://probe.dev/draw/windRose?station=vp2&sensors=wind&Since=2012-10-15T00:00:00&StepUnit=DAY&StepNbr=6;
d3.json(url, function(d) {
console.log(d); // print NULL in console
}
Run Code Online (Sandbox Code Playgroud)
但它适用于
$.getJSON(url, function(d) {
console.log(d); // print my data object correctly
}
Run Code Online (Sandbox Code Playgroud)
我的PHP代码是:
<?php
@ob_end_clean();
header('Content-Type: "application/json"');
header('Content-Disposition: attachment; filename="data.json"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
header("Content-Length: ".strlen($data));
exit($data);
Run Code Online (Sandbox Code Playgroud)
我不明白为什么d3.json不起作用?
我无法使用v2,我移动到d3js.v3并且它有效.
v3中的回调函数有两个参数:
d3.json(url, function(error, json) {
if (error) return console.warn(error);
else ...;
}
Run Code Online (Sandbox Code Playgroud)