我正在使用下面的代码片断将double数组的java数组返回给另一个javascript函数。从javascript函数返回一个值
var getCredits = (function() {
console.log('Getting credits');
$.ajax({
type : 'GET',
url : rootURL+"/getCredits",
dataType : "json", // data type of response
success : function(data){
var array = [];
console.log('Credits data = '+data);
for(var x in data){
console.log('x = '+data[x]);
array.push(data[x]);
}
console.log('credits array is '+array);
return array;
}
});
});
var getDebits = (function() {
var myArray = [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8];
console.log('debits array is '+myArray);
return myArray;
});
当我运行的代码 - 日志以下 -
“我的生成图形” myMain.js:110 “获得信用” myMain.js:149 “借记阵列是3.9, 4.2,5.7,8.5,11.9,15.2,17,16.6,14.2,10.3,6.6,4.8“ myMain.js:169”Credits Credits = 10.7,20.5“myMain.js:156”x = 10.7“ myMain.js :158“x = 20.5”myMain.js:158“学分数组是10.7,20.5”
the getD ebit功能基本上就是我想要的getCredits功能。 从它看起来像它的什么,我想日志 - 但我将其传递到另一个函数,它看起来像 -
var generateMyGraph = (function() {
console.log("generating my graph");
$('#myLineGraph').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Finances per month'
},
subtitle: {
text: 'Credit and Debit per month'
},
xAxis: {
categories: ['Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug','Sep','Oct']
},
yAxis: {
title: {
text: 'Euro (€)'
}
},
plotOptions: {
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: true
}
},
series: [{
name: 'Credit',
data: getCredits()
}, {
name: 'Debit',
data: getDebits()
}]
});
});
和它不工作,任何想法?提前致谢!
看起来像着名的dup http://stackoverflow.com/quest离子/ 14220321 /如何对返回的响应-从-AN-Ajax的呼叫 – elclanrs 2014-10-26 21:39:35