0

This is a problem on Free Code Camp that I'm trying to solve but no one can help me on the help box there, it seems. The problem is something that should be very straightforward but I just cannot see what the problem is.

I'm doing the Random Quote Generator challenge and decided to create my own .json file on my own web space to get the quotes from. Such test files can be found here:

http://www.deanius.co.uk/json/cats.json
http://www.deanius.co.uk/json/RandomQuoteGenerator.json
http://www.deanius.co.uk/json/RandomQuoteGenerator_original.json

I thought the easy way to test whether or not this data (which is parsed correctly) can be obtained would be to change the path in the Free Code Camp lesson called "Get JSON with the jQuery getJSON Method", which can be found at https://www.freecodecamp.com/challenges/get-json-with-the-jquery-getjson-method ... thinking the simple solution is add the code on the left where it says ("Only change code below this line") and change the /json/cats.json to one of the paths above.

But... even when I change the path to just the http://www.deanius.co.uk/json/cats.json one (which is the exact same data as /json/cats.json) it does nothing. I thought this could be a limitation of FCC's testing abilities so took the JS and HTML from the lesson and stuck them in their respective boxes in Codepen, with the jQuery.min.js external script added. It still does nothing.

There's got to be a very simple answer to this. Does anybody know what it is?

Thanks

  • You are bumping into cross domain scripting limitations. Try JSONP data type with jQuery's [ajax](http://api.jquery.com/jQuery.ajax/) function. – trincot May 24 '16 at 11:29
  • I'll try to figure out what you mean but am I not supposed to build on what FCC have taught me? What I mean is, shouldn't I be using the methods and functions they've taught me, as that is the point? Edit: I've looked up what you mean and I get it - I can't pull info from another site onto FCC. But that doesn't explain why I can't when I stick the code in codepen. After all, the quotes have to come from somewhere other than the codepen site... – keeperoftheflame May 24 '16 at 11:33
  • See [this question and answer](http://stackoverflow.com/questions/5943630/basic-example-of-using-ajax-with-jsonp). Because you fetch the JSON from another server than where your script is running, there are limitations that can kick in, although it depends on the server where the JSON is hosted . It could be configured to allow your scenario. – trincot May 24 '16 at 11:36
  • In the end I sorted it by creating a second pen on codepen with the JSON file in the JS box - then I used that JS (the web address of the pen with .js tacked onto the end) in the random quote generator pen - just put the address for the other pen .js file into the getJSON function. – keeperoftheflame May 24 '16 at 12:11

0 Answers0