简体   繁体   English

如何从JavaScript远程网站获取数据?

[英]how can i get data from a remote website in JavaScript?

I want to get the data from http://whatismyip.com/automation/n09230945.asp using JavaScript. 我想使用JavaScript从http://whatismyip.com/automation/n09230945.asp获取数据。 How can I do this? 我怎样才能做到这一点?

I can get the data from ASP.NET by using WebClient class but how can we get data using JavaScript? 我可以使用WebClient类从ASP.NET获取数据但是如何使用JavaScript获取数据?

You will need to use AJAX . 您需要使用AJAX However, unless the service provides a JSONP interface, AJAX is limited to getting pages from the same domain as the page it runs on. 但是,除非服务提供JSONP接口,否则AJAX仅限于从与其运行的页面相同的域中获取页面。 See: Same origin policy . 请参阅: 同源政策

Use YQL - http://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_html_scraper 使用YQL - http://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_html_scraper

It essentially acts as a proxy to grab page data for you through their service. 它本质上充当代理,通过他们的服务为您抓取页面数据。 You can interact with it solely with JavaScript. 您只能使用JavaScript与其进行交互。

绕过相同原始策略的方法是在自己的服务器上用ASP编写一个脚本来获取数据,然后通过页面中的AJAX获取该脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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