我有這個功能如何在javascript函數中返回json對象?
function getTags(level){
$.getJSON("php/get-tags.php", { "parent": level }, function(json) {
return json;
});
}
我打電話這個功能
$(function(){
var tags = getTags('0');
});
的問題是,在功能getTags()
返回json
就像
{"tags":["Mathematics","Science","Arts","Engineering","Law","Design"]}
但在var tags = getTags('0')
,捕獲返回值,它得到價值。
我返回的值的方式不正確嗎?
的可能重複[異步JavaScript的返回值與jQuery /分配](http://stackoverflow.com/questions/7779697/javascript -asynchronous-return-value-assignment-with-jquery) – 2012-01-11 21:10:04