I just googled around, hacked at my function, etc.
For some reason I ended up trying this solution (i.e. setting
thisStory inside the getJSON callback instead of using the thisStory =
getJSON() way., and it works ALMOST:
<script type="text/javascript"> //<![CDATA[
var thisStory = {};
$.getJSON("javascript/test.js", function(jsonFile){ thisStory =
jsonFile; });
//]]></script>
So the page works entirely, except for the document.write… which
actually shouldn't work, because that's executing prior to $.getJSON
defining thisStory. So, no biggie - I take a look at some normal
jquery stuff and switch to using:
<p class="attribution">
<script type="text/javascript"
language="JavaScript">
$('.attribution').append('<i>' +
thisStory.title + '</i>' + ' by
' + thisStory.author + '<br><br>');
</script>
</p>
But this is still being written to the document as "undefined by
undefined." When I check thisStory using Firebug, all of the values
are there, so this must still be executing prior to the value
assignment.
So I changed my script to:
<script type="text/javascript"> //<![CDATA[
var thisStory = {};
$.getJSON("javascript/test.js", function(jsonFile) {
thisStory = jsonFile;
$('.attribution').append('<i>' + thisStory.title + '</i>' +
' by ' + thisStory.author + '<br><br>');
});
//]]></script>
and now it works fine. So then I think I just need to do all of the
value assignment in the $.getJSON block.
But other scripts (like $('.frame').click for example) are getting the
values of thisStory fine. Can anyone explain (or point to an
explanation of why a $('.attribution').append in the body doesn't work
but a $('.frame').click does?
As always, thanks!