loadJSON(): json vs jsonp datatype?

The reference info on http://p5js.org/reference/#p5/loadJSON is a bit skimpy. The third argument, datatype, can be "json" or "jsonp". Can someone expand on when it's appropriate to use JSONP? Or is that better answered outside of the p5 forum?

I understand that jsonp is "json with padding", and designed to avoid some cross-domain restrictions. I was getting Access-Control-Allow-Origin errors with my loadJSON() call, so I added "jsonp" as the third argument to see what would happen. Now my requests are sent with a "?callback=reqwest_1456796177243" query string tacked on the end. (And since I wrote the server, I know it's not prepared to handle that query string.)

So: How and when are you supposed to use the "jsonp" argument to loadJSON()?

Tagged:

Answers

  • Answer ✓

    As per my other replay: JSONP is an accepted hack for getting round cross-domain restrictions in browsers; so is going to be needed if you can't add CORS to your server. It's well established and well documented: this stackoverflow answer is very clear.

    It does come with some security concerns which is one reason CORS is generally preferable.

Sign In or Register to comment.