我正在尝试获取我的获取文本给我的数据我从php中的api生成2个json文件我用我的函数获取它们并且可以将其显示为警报但我想在函数dessin中用它干燥图表()但我无法获得我的dataid和datanom的值 谢谢你的帮助;)
getText = function(url, callback) // How can I use this callback?
{
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
callback(request.responseText); // Another callback here
}
};
request.open('GET', url);
request.send();
}
function mycallback(dataid) { //this is the data that am trying to use in
alert(dataid);
}
function mycallbacknom(datanom) {
var datajsonnom = JSON.parse(datanom);
alert(datajsonnom);
}
getText('http://localhost/id.json',mycallback);
getText('http://localhost/nom.json',mycallbacknom);
function dessin() {
//var lab = datajsonnom;
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: dataid, //i want to put the dataid here
datasets: [{
label: '# of Votes',
data: data, // and the datanom here