Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the reason i have to use jsonp?

What's the reason i have to use jsonp?

A few days ago i asked why i have no response from a rest server with jquery. The reason was that i must use JSONP. I tested that with a own server and it worked.

Now i have to convince my college's who have control of the right server that the output have to be JSONP instead of json.

Only i don't now exactly why i must use JSONP? And is this only a jquery problem or is it not possible with javascript at all?

Can anyone help me with these questions? Thanks

like image 314
robind38 Avatar asked Dec 13 '22 04:12

robind38


1 Answers

JSONP is used to get data via AJAX cross-domain. Well, not exactly, JSONP is actually a bit of a "hack".

AJAX requests only work on the same domain, but <script> tags can be included from any domain. This is what JSONP is, it's actually a Javascript file, that gets added as a <script> tag.

That's why in JSONP, it's callback({data: value}), this is a script that gets executed.

like image 66
Rocket Hazmat Avatar answered Dec 25 '22 21:12

Rocket Hazmat