Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Cesar Vanbuskirk
Cesar Vanbuskirk
6,672 Points

JSON VS JSONP

Hello everyone, I've been kind of confused about these two and what their differences are and when to use either one. If anyone could give me a quick explanation I'd appreciate it thanks!

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Cesar;

JSONP is basically a workaround that bypasses cross domain scripting policies. Instead of making an AJAX call and requesting JSON, you actually create a script tag, with the get call as the SRC attributes of the script tag, which is allowed to call across domains, the difference is, instead of JSON, you get JSON wrapped in a function call, so when the script tag completes, it runs the call which basically is passing the JSON you wanted in the first place.

Ken

Cesar Vanbuskirk
Cesar Vanbuskirk
6,672 Points

Oh wow that's a lot to take in thanks for the explanation!