1
可能重複:
Why is this function returning 「undefined」?如何讓JavaScript函數返回Ajax結果?
假設我有以下JS功能:
function getTileData(x, y, loc_slug) {
$.ajax({
url: "/sys/map-admin/show-location/"+loc_slug+"/get-tile/"+x+"-"+y+"/",
success: function(data){
alert(data); // Object, that's correct.
**What do I need to make the whole getTileData function return data?**
}
});
}
,我把它叫做另一個函數內的類似
tile = getTileData(1, 2, 'asd');
alert(tile); // undefined