Using JSONP to make cross-domain requests

The JSONP mechanism of remote invocation relies on the fact that browsers can execute JavaScript files from any domain irrespective of the source of origin as long as the script is included via the <script> tag.

In JSONP, instead of making a direct request to a server, a dynamic <script> tag is generated, with the src attribute set to the server endpoint that needs to be invoked. This <script> tag, when appended to the browser's DOM, causes a request to be made to the target server.

The server then needs to send a response in a specific format, wrapping the response content inside a function invocation code (this extra padding around the response data gives this technique the name JSONP).

The Angular ...

Get Building Large-Scale Web Applications with Angular now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.