setting jQuery .data() within .getJSON callback

Posted by hackmaster.a on Stack Overflow See other posts from Stack Overflow or by hackmaster.a
Published on 2010-06-09T00:16:22Z Indexed on 2010/06/09 0:22 UTC
Read the original article Hit count: 567

Filed under:
|

I'm doing a couple of .getJSON calls and if any one of them succeeds, I'm trying to set a bool to true so I can then do some other stuff elsewhere on the page. I was trying to use jquery's .data() function, but I don't seem able to set it from inside the .getJSON callback. for example:

$('#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'));

prints false, even when I know the data came through. I thought this would work since .data() uses the cache to store the key/value pair. how can i flag successes?? appreciate any assistance!!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about getjson