Files
freeCodeCamp/guide/english/miscellaneous/learn-about-jsonp/index.md
Lipis 5818b277c4 Replace Jquery -> jQuery (#35184)
* Replace Jquery -> jQuery

* JQuery

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update index.md

* Update guide/russian/jquery/jquery-html-method/index.md

Co-Authored-By: lipis <lipiridis@gmail.com>

* Update guide/russian/jquery/jquery-html-method/index.md

Co-Authored-By: lipis <lipiridis@gmail.com>
2019-02-14 06:59:19 -08:00

1.4 KiB

title
title
Learn About Jsonp

JSONP

JSONP stands for "JSON with padding". Let's say you want to make AJAX requests to a different domain. Well, you can't do this with XMLHttpRequest, as you normally would, but you CAN do this with script tags, as seen on StackOverflow:

script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://www.someWebApiServer.com/some-data';

But this is ugly, now we have to get elements of a JSON out of a script tag, gross. Luckily, the creators of JSONP were thinking ahead, so instead of setting our scripts as we did above, we do this:

script.src = 'http://www.someWebApiServer.com/some-data?callback=my_callback';

This triggers an automatic callback after the data has loaded, creating a function with the data desired inside of it.

More Information: