-1
我有問題,該行的Javascript全局變量 - 控制檯日誌未定義
console.log("xxx" + stanica1);
結果是xxxundefined,但我需要返回值stanica1Prosjek/24;
function podatciPrethodniDan(handleData) {
var parametar = $("#parametar1").val();
$.ajax({
type: "POST",
url: "php/getPreviousDayData.php",
dataType: "json",
data: {
parametar: parametar
},
success: function(data) {
handleData(data);
} //end of success
}); //end of ajax
}
function style(feature) {
var stanica1;
stanica1 = podatciPrethodniDan(function(output) {
//console.log(output);
var stanica1Prosjek = 0;
var stanica2Prosjek = 0;
var stanica3Prosjek = 0;
var stanica4Prosjek = 0;
//console.log(output.length);
for (i = 0; i < output.length; i++) {
//console.log("petlja " + i);
if (i < 24) {
stanica1Prosjek = stanica1Prosjek + parseFloat(output[i].par);
//console.log(stanica1Prosjek + " " + i);
}
}
console.log("in" + stanica1Prosjek);
return stanica1Prosjek/24;
});
console.log("xxx" + stanica1);
}
看起來不像你曾經調用'stanical',你只是定義它 –
stanica1 = podatciPrethodniDan(函數(輸出)... –
@tcooc沒有重複,OP?正在使用回調 –