JSON problem

Hi All, I'm trying to read this info http://ontology.sofiethic.org/jsons/ent using the standard example of http://p5js.org/learn/demos/Hello_P5_Weather.php But I'm getting an error that i don't have any idea what is causing it.

[Error] TypeError: undefined is not an object (evaluating 'resp.responseText') success (p5.min.js, line 4) onreadystatechange (p5.min.js, line 4)

Thanks for the help

David

Tagged:

Answers

  • Even though the error is happening inside "p5.min.js" itself, it's still much probably due to something wrong in your own sketch.
    Asking for troubleshooting help w/o posting the problematic code is unfruitful!

  • Answer ✓

    As @GoToLoop says: you'll need to post some code for us to be able to properly help. I just tried to request the data and didn't get very far:

    XMLHttpRequest cannot load http://ontology.sofiethic.org/jsons/ent. No 'Access-Control-Allow-Origin' header is present on the requested resource.

    Is this on your domain and are you testing with files hosted on the same web server?

  • Hey blindfish! Now I understand the error, it works well if the example is online and I had to change the html routing to make it work local. Thanks for the help, it is resolved

  • Answer ✓

    No worries: this is a common issue when testing ajax requests: not much will work locally because of browser security restrictions...

    I also think the p5js example needs updating, or maybe even the loadJSON method. You should always test that you've got valid data before trying to parse it. You could implement that in your callback function, but it would be better if loadJSON returned success/error flags for you to check against; since confirming valid JSON data is returned is going to be a common requirement ;)

Sign In or Register to comment.