Request external website data using jQuery ajax

♀尐吖头ヾ 提交于 2019-12-04 15:24:01

You should look into JSONP, or more likely use some sort of intermediary, like a PHP script (so same origin) that uses cURL or file_get_contents to access the third party site

for instance:

<?php
$file=file_get_contents('http://some_domain_not_yours.com/somefile');
echo $file;
?>

you should do this via PHP i.e. loading via PHP include the external site and than parse it in your PHP.

You cannot do this via jQuery, basically you can't make a client retrive remote content without a server side to filter it. If a client could access freely remote content you won't have any control on data accesses for the SOP you always need a server in between to guarantee the content management and filtering, this can be either your server or a remote server (like an API provider). To assure this, you can only share JSON objects cross domains, JSON objects are objects created via PHP (for example) so you can't get a JSON object without a server script. The other way (your server is between) is you make a server retriving remote content and then givin' it to your client in any format you like.

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