Java Reference
In-Depth Information
JSON With Padding
JSONP or JSON with padding is a very common technique of transporting data as it allows
the same-origin policy to be bypassed without using CORS. It involves sending a JSON
string wrapped in a callback function that is then injected into a <script> tag. The
same-origin policy doesn't apply to <script> tags, and because the callback function has
already been defined in the domain requesting the data, all the data wrapped in the function
will be available in that domain by referencing the callback function.
Warning: The Server Must Support JSONP
The server responding to the request must support JSONP requests and return
a callback function. The technique will fail to work if normal JSON data is
JSONP in Action
To demonstrate using JSONP, we'll create another small web page. In a new folder, create a
file called jsonp.htm and add the following HTML code:
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>JSONP Example</title>
<button id="send">Request Text</button>
<div id="output">
Ajax response will appear here
<script src="scripts.js"></script>
Search WWH ::

Custom Search