Wednesday, 14 June 2017

javascript - What is JSONP, and why was it created?



I understand JSON, but not JSONP. Wikipedia's document on JSON is (was) the top search result for JSONP. It says this:





JSONP or "JSON with padding" is a JSON extension wherein a prefix is specified as an input argument of the call itself.




Huh? What call? That doesn't make any sense to me. JSON is a data format. There's no call.



The 2nd search result is from some guy named Remy, who writes this about JSONP:




JSONP is script tag injection, passing the response from the server in to a user specified function.





I can sort of understand that, but it's still not making any sense.






So what is JSONP? Why was it created (what problem does it solve)? And why would I use it?







Addendum: I've just created a new page for JSONP on Wikipedia; it now has a clear and thorough description of JSONP, based on jvenema's answer.


Answer



It's actually not too complicated...



Say you're on domain example.com, and you want to make a request to domain example.net. To do so, you need to cross domain boundaries, a no-no in most of browserland.



The one item that bypasses this limitation is

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...