我的网站上有一个图表js! 我在从外部 PHP 页面获取数据时遇到问题。有人可以帮助我吗?
var result = [];
$.ajax({
url: 'x.php',
dataType: 'text',
async: false,
success: function(data) {
items = data
}
});
result = items
var dataProcessosAtivos = [
result
];
原变量如下:
var dataProcessosAtivos = [
[0, 4],
[1, 8],
[2, 0],
[3, 0],
[4, 0],
[5, 0],
[6, 0],
[7, 0],
[8, 0],
[9, 0],
[10, 0],
[11, 0]
];
这是一个 x.php:
$json = "[0,87],[1, 14],[2, 16],[3, 0],[4, 0],[5, 0],[6, 0],[7, 0],[8, 0],[9, 0],[10, 0],[11, 0]";
echo json_encode($json);
最佳答案
将 php 文件内容更改为以下内容。如果它是 DOM 中的现有图表,请确保图表在设置结果后重新绘制。
// This tells the bellow content is JSON
header ('content-type: application/json');
// Actual PHP array
$json = [[0,87],[1, 14],[5, 0],[6, 0],[7, 0],[8, 0],[9, 0],[10, 0],[11, 0]];
// Printing JSON string
echo json_encode($json);
关于javascript - 带有外部 ajax 数据的图表 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37152166/