1

The below call failed :

https://api.twitch.tv/kraken/streams/MedryBW?client_id=pzaazcrab42neperff77e2elkrqrj4y"

This one passed :

https://api.twitch.tv/kraken/streams/MedryBW?client_id=pzaazcrab42neperff77e2elkrqrj4y&callback=?"

what does this callback=? do ?

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Vinodh Thiagarajan
  • 758
  • 3
  • 9
  • 19
  • 1
    It makes it use [JSONP](https://en.wikipedia.org/wiki/JSONP), a way to bypass the [same-origin policy](https://en.wikipedia.org/wiki/Same-origin_policy). – gen_Eric Sep 10 '15 at 16:06
  • PROTIP: When posting a question, just saying "failed" doesn't help us help you. You should show your code and any error messages you see in your console. You should explain what "failed" means; what you expect the code to do versus what it does do. – gen_Eric Sep 10 '15 at 16:07

1 Answers1

2

The callback=? is a "magic" part of the URL that jQuery recognises, and it changes how the request is made.

The callback parameter in the URL is used in a JSONP request, so jQuery change the request from using XHR (XMLHTTPRequest) to using a script element. It also changes callback=? in the URL to use a unique function name, something like callback=callback87624827346.

As the request is not using XHR, it's not subject to the same origin policy. That's why you can make the request (without setting up CORS on the server to make the browser allow the request).

Guffa
  • 687,336
  • 108
  • 737
  • 1,005