1

I can't seem to find a definitive answer on this -- what does the p in JSONP stand for?. The candidates I've found so far are padding and prints. Anyone know where the JSONP name came from?

1

5 Answers 5

8

Padding.

from http://en.wikipedia.org/wiki/JSONP

JSONP or "JSON with padding" is a complement to the base JSON data format, a pattern of usage allowing a page to request data from a server in a different domain. JSONP is a solution to this problem, forming an alternative to a more recent method called Cross-Origin Resource Sharing. Padding

While the padding (prefix) is typically the name of a callback function that is defined within the execution context of the browser, it may also be a variable assignment, an if statement, or any other Javascript statement. The response to a JSONP request (namely, a request following the JSONP usage pattern) is not JSON and is not parsed as JSON; the returned payload can be any arbitrary JavaScript expression, and it does not need to include any JSON at all. But conventionally, it is a Javascript fragment that invokes a function call on some JSON-formatted data.

Said differently, the typical use of JSONP provides cross-domain access to an existing JSON API, by wrapping a JSON payload in a function call.

Hope that helped. Google wins!

1
  • The difficulty is that knowing it stands for padding still leaves you wondering what that means. Padding doesn't usually mean what it means in the context of JSONP. It's poorly named. There's nothing to be done now except get over it. :-) Commented Mar 29, 2021 at 9:01
3

Stone,

What I know, it stands for 'Padding'. There is a explaination about it on Wikipedia: JsonP

What it does?

It gives you the possibility to make a CROSS-DOMAIN request and get JSON data returned. Normally via the HTML script tag you call for another JavaScript.

But JsonP provide you a callback function and you can return noraml Json response.

Example:

You create a script tag:

  • <script type="text/javascript" scr="http://anotherDomain/Car?CarId=5&jsonp=GiveCarResponse"></script>

In this script the GiveCarResponse is the callback function on the other Domain. Invoking this function will result in a Json response. In example:

{"CarId":5, "Brand":"BMVV", "GAS": false}

Does this make sense?

1

From wikipedia, it stands for "padding" (or with padding).

http://en.wikipedia.org/wiki/JSONP

1

Umm ... you've seen the wikipedia page, and you mistrust its accuracy?

This standards site seems to confirm the "with padding".

0

It basically means to add a calling function around JSON. AJAX can be called from your own server only and is not a cross domain. So to load data from different servers at client side, you make a JSONP request, basically you load a normal javascript file from other server just like you include a normal javascript file. Bust as JSON is not a valid javascript file, JSON is wrapped up in a function call to make it valid js file. the wrapped up function (already in your code) then extracts that data and show it on your page.

Not the answer you're looking for? Browse other questions tagged or ask your own question.