Old TechnologiesLesson 52Free preview
JS JSONP
This lesson is part of JavaScript · All levels
Summary
JSONP (JSON with Padding) is an old technique for extracting data from other domains in the era before CORS was available, by loading a <script> tag whose URL includes a callback name. The server will call the callback function and deliver the data as an argument. Due to security limitations and only supporting GET, JSONP has now been completely replaced by Fetch API with CORS.
Key points
- JSONP uses <script> tags that are not subject to the same-origin rule
- The URL request includes a callback name, for example callback=tangani
- The server responds by calling the function tangani({...})
- It's now safer to use a fetch with CORS; JSONP is just for old systems.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.