1
setTimeout
が必要でない可能性がある他の方法はありますか?ajaxコールバック関数でsetTimeoutを避ける
function initialize(){
$.get('test.xml', function(xml){
//do some stuff with xml like...
var icons = xml.documentElement.getElementsByTagName("icon");
for(var i = 0; i < icons.length; i++) {
var iconImage = icons[i].getAttribute("image"),
}
//do more things to create markers like...
markers.push(marker);
//try to add markers to map
//this will give an error
addMarkers(markers);
//setTimeout makes it work
setTimeout("addMarkers(markers)", 300);
//is there any way to avoid the timeout?
});
}
どのようなエラーが発生しますか? 'マーカー 'はどこから来たのでしょうか? –
関連:[JavaScriptタイマーのしくみ] –
Googleマップ用のmarkerManagerユーティリティでAPIエラーが発生する – Mike