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 AJAX Basics (retiring) AJAX and APIs Making the AJAX Request

Kelvin Zhao
Kelvin Zhao
10,418 Points

When to know to use ?jsoncallback=?

When do we know to add the ?jsoncallback=? to the end of the url?

Also doesn't the 'format' already request a json format, why do we need to add that?

If we don't use that, what happens, what other way do we script the request (I'm assuming that means the get back isn't in the json format?)

Thanks in advance!

1 Answer

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Hi Kelvin Zhao ,

You use the ?jsoncallback=? when using jQuery's getJSON() method. That tells jQuery that it needs to make a JSONP request, not a normal AJAX request. JSONP isn't exactly AJAX -- it actually creates a new script tag that embeds JavaScript from Flickr. If you remove the ?jsoncallback=? from the URL, then you will get an error because the page is then making a cross-domain AJAX request which is forbidden by the browser's "Same-origin" policy.

The part where you set the format to json is just the information you send to Flickr -- it tells flickr that you want JSON data in return. Setting the format to json has no affect on how the request is made.

nitin suresh
nitin suresh
5,691 Points

Hello @davemcfarland I love the course !. How can we do cross-domain request now with CORS?