1

I'm loading a large number of items on a page through JSON, but it isn't working. This is my first time using JSON and I figured JSON was just a big object so I copied my object that I had before in a variable into a file and names it fun.js.

You can check out the JSON here:

http://justpaste.it/15zc

I'm using jQuery to get the JSON:

$.getJSON('fun.js', function(data){
alert(data)
});

Nothing is being alert, in the matter of fact...the alert isn't happening at all. Anyone know why?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Shawn31313
  • 5,978
  • 4
  • 38
  • 80

2 Answers2

6

For starters, your JSON doesnt validate. Go paste it here and fix your errors: http://jsonformatter.curiousconcept.com/

Secondly, user jQuery.Ajax to which you can pass onError parameter so you'll get a warning that JSON didn't go through.

Jure C.
  • 3,013
  • 28
  • 33
  • We can also just watch the network requests with something like Chrome's developer tools rather than hack in our own on-error callback exclusively for debugging. – Matchu Jul 24 '12 at 22:25
  • Oh, i didn't know you need to use double quotes on everything. – Shawn31313 Jul 24 '12 at 22:27
0

Have you validated that the JSON is the issue? Open up Firebug or Chrome Dev Tools and refresh the page. You may see a message that the file wasn't found or there was a parsing exception or a security error.

  • If the file isn't found, you can fix that in the code.
  • If there is a parsing error, use a JSON validator.
  • If there is a security issue, see my answer to Get a JSON file from URL and display. You need to update your server policy or configure your browser to allow access to file URL's in your tests through.
Community
  • 1
  • 1
Brian Nickel
  • 26,890
  • 5
  • 80
  • 110