我有这个功能如何在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