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 trialKonstantinos Pedarakis
21,301 Pointswhat is the jsoncallback=? part of the query string?
Ok! i've manage to complete all the steps and pretty much it was easy for me to understad cause im not new in programming in general, but because im not involved very much with API's that part at the end of the url confused me. what is that jsoncallback part of the query string and where do we use it? why do we use it? we use it every time? and why? Thanks for any clarification.
1 Answer
Arturo Alviar
15,739 PointsHi Konstantinos,
The jsoncallback=? part of a query is a special parameter that requests JSONP (JSON with Padding).
When doing an AJAX request, you are restricted by the "Same-origin" policy meaning that whatever you request must be in the same domain from where the request was made. With this parameter, the query does not perform a regular AJAX request.
With JSONP, we can get around the "Same-origin" policy and successfully obtain data from a different origin (i.e. a different website).
Hope this helps!
Konstantinos Pedarakis
21,301 PointsKonstantinos Pedarakis
21,301 PointsHi Arturo Alviar , Thanks for taking the time to reply. Yes, this makes more sense now. Another question that just came up, this jasoncallback=? part or the query string is the same everytime that i want to make a JSONP request? i mean is a standard part of the string when i am about to get around the "Same-origin" policy? And is everywhere the same? i mean if i was making some requests, not to flickr lets say, but to Facebook or Twitter, the jsoncallback=? would be the same there as well? Thanks.
Arturo Alviar
15,739 PointsArturo Alviar
15,739 PointsHi Konstantinos,
Generally the JSONP parameter is callback=? but it can vary depending on the server-side API (although usually the convention is callback=?).
With Facebook and Twitter, making JSONP requests can be done using the callback=? parameter.
Konstantinos Pedarakis
21,301 PointsKonstantinos Pedarakis
21,301 PointsThanks a lot! Arturo Alviar