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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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
now that the JSON is valid, maybe this will help: stackoverflow.com/questions/3030321/…
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.