Monday 16 October 2017

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

itemprop="text">


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 href="http://remysharp.com/2007/10/08/what-is-jsonp/" rel="noreferrer">2nd search
result is from some guy named href="https://stackoverflow.com/users/22617/remy-sharp">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 href="https://stackoverflow.com/users/25330/jvenema">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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...