jasonp cross domain request “wrapping json into a callback method”

社会主义新天地 提交于 2019-12-04 15:36:42

Your PHP script is returning JSONP and not JSONP. To make it working cross-domain you must actually modify your PHP to return a call to a callback function.

So you must make sure that the PHP code is returning data in a form callback(data);.

$jsdata = ($_GET['callback'].'('.json_encode($data).');'); 

Change your JavaScript .getJSON() call to:

$.getJSON("http://www.freeenergymedia.com/getxml2.php?callback=?", function(json) {
  // ... rest of the code
});

jQuery will insert into the URL generated callback name.

See documentation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!