0
我正在使用jQuery $ .getJSON(..)来获得一些json。
传递值显示我“undefined”。
有没有办法做到这一点?
getTopMenuJson : function(currentPage) {
if(currentPage == null) currentPage = 1;
var retJSON;
$.getJSON(
requestURLs.topMenuJson,
{
'ITEM_PER_PAGE' : TopMenuHandler.ITEM_PER_PAGE,
'CURRENT_PAGE' : currentPage
},
function(JSON) {
//alert(JSON); **<--This gives me result (Object)**
retJSON = JSON;
}
);
**alert(retJSON); //<!-- This doesn't, but Undefined**
},
嗯..我认为这个问题是当试图将值赋给'retJSON'。而不是这样做,他正在重新声明'retJSON' var。 – lu1s
@ lu1s,即使他在回调中使用了'retJSON = JSON',那也不行,:)但是,你有一点,我会编辑我的代码片段 –
我不完全理解,但你的来源完美的作品! –