简体   繁体   中英

file_Get_contents in javascript

我想使用从我的网站执行的JavaScript从其他网站获取数据。

PHPJS网站上有一些将PHP函数转换为Javascript的很好的方法。

In general, unless they expose the data with JSON-P , you can't thanks to the security considerations imposed by the same origin policy .

Recent browsers support a permissions system where a remote site can allow JavaScript running on a remote site to make a request. Flash provides a similar system, so can act as an intermediary. Both of these require the cooperation of the remote site.

The usual work around is to use a proxy service, either running on your own system (so JS makes the request to the same server, which fetches the data from the remote site) or a third-party service like YQL .

Javascript is limited by the same-domain security policy. The only way to get data from other sites is to use JSONP or build a proxy on your own host that lets you curl content from other sites.

Use jQuery:

$.post( 'http://some.website.com/file.js', function(result){
    alert(result);
});

You may not fetch anything but JavaScript or JSON.

Or try this answer: How do I send a cross-domain POST request via JavaScript?

必须在服务器端完成-发送ajax请求 ,运行所需的PHP,并检查responseText属性以查看结果。

That really depends on what you mean by "data". Try using AJAX if its just for simple requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM