JavaScript: How do I create JSONP?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a two domains, example1.com and example2.com From example1.com, I would like call a JSON API I have on example2.com. Knowing that this is not allowed, it occurred to me - this is exactly why JSON P was created. Question is, how do I modify my JSON API to make it JSONP capable? Basically, how do I create the callback api? UPDATE My server side language is PHP 回答1: It is simple. Simply accept a parameter called callback in the GET. Then wrap the callback JavaScript function around your data. Example in PHP: <?php $data = '{}'; // json