【发布时间】:2010-06-09 08:43:23
【问题描述】:
我正在执行几个 .getJSON 调用,如果其中任何一个调用成功,我会尝试将 bool 设置为 true,这样我就可以在页面的其他位置执行其他操作。我试图使用 jquery 的 .data() 函数,但我似乎无法从 .getJSON 回调中设置它。例如:
$('#citations_button').data('citations', false);
$.getJSON(apaurl, function(data) {
$('#apacite').html("<td class=\"bibInfoLabel\">APA Citation</td><td class=\"bibInfoData\">"+data+"</td>");
$('#citations_button').data('citations', true);
}, "html");
// other .getJSONs look like above...
console.log("citations? "+$('#citations_button').data('citations'));
打印错误,即使我知道数据已通过。我认为这会起作用,因为 .data() 使用缓存来存储键/值对。我如何标记成功?感谢任何帮助!
【问题讨论】:
-
getJSON是一个异步调用,你确定它在你调用console.log之前返回吗?