我想在匿名函数之外检索一个变量,目前,我有这个:
function recupererFichier(callback, params){
$.ajax({
url : 'map.php',
dataType: 'json',
success: function (data) {
//console.log(data)
callback(data, params);
}
});
}
function test() {
var recup = [];
recupererFichier(
function (data, params) {
console.log(recup)
console.log("data", data.length);
for (var i = 0; i < data.length; i++){
recup[i] = data[i];
}
console.log(recup) //["breche_de_roland_.gpx", "casque_lheris_.gpx", "col_d_arrious.gpx", "lac_combales.gpx", "lac_d_isabe_.gpx", "lac_de_gaube_.gpx", "lac_de_pombie_.gpx", "pic_midi_de_bigorre.gpx", "refuge_lac_migouelous.gpx", "refuge_wallon.gpx", "tour_des_lacs_-_lac_d_ayous_.gpx"]
});
//Retrieve array here
console.log(recup) //undefined
}
我希望在匿名函数之外生成数组。那可能吗? 感谢