0

I'm new to js and jQuery, so still very much feeling around ... but this has foxed me for a couple of days.

I am trying to do this 101 thing - to use jQuery.getJson to read and then do something with the file that's over here: http://www.metakarma.org/agame.json

I can't figure out where the error is - in my js or in the file.

Here's what I'm trying in the js:

<script type="text/javascript">
    $(document).ready(function () {
        $.getJSON("http://www.metakarma.org/agame.json", function (data) {
            $.each(data.moves, function (i, amove)
            $("#debug").append(amove.role + ' ' + amove.message + '<p>');
            });
        });
</script>

When I use the js example to get the first 3 cat photos from Flickr on the jQuery reference page over here - http://docs.jquery.com/Getjson - it basically works as expected. But my code/file combo above produces complete silence.

I guess I have 2 questions: 1. how do I efficiently debug this? 2. what is the bug?

Very grateful for pointers out of my current hole! Tony

Colin Brock
  • 21,267
  • 9
  • 46
  • 61

1 Answers1

0

You can use a tool such as jsonlint.com to validate the JSON (yours is not due to the surrounding parentheses) to narrow it down to handling or data.

I'd also use a tool such as firebug/wireshark/httpfox, etc to watch the network traffic to see if your calls are returning data, or what else might be happening.

Robot Woods
  • 5,677
  • 2
  • 21
  • 30
  • Thank you. OK - took out the surrounding parentheses and now have valid JSON but still silence. Will now see what I can see in firebug – Tony Curzon Price Jun 09 '12 at 00:47
  • now that the JSON is valid, maybe this will help: http://stackoverflow.com/questions/3030321/jquery-each-loop-with-json-array – Robot Woods Jun 09 '12 at 00:53
  • OK - the cross-server scripting restrictions were the cause of my problem here. First I had to not be running the js locally on MAMP and trying to read the json file off the server - I caught that by looking at the JS console in Chrome. – Tony Curzon Price Jun 09 '12 at 01:01