简体   繁体   English

从网页获取数据,然后在另一个网页上显示

[英]Get Data from a Web Page, then Display It On Another Web Page

I want to get data from an HTML web page, then display it in a Div on another HTML web page, with jQuery. 我想从HTML网页获取数据,然后使用jQuery将其显示在另一个HTML网页上的Div中。

I tried jQuery's get(), load(), and ajax() methods, but unable to get the data. 我尝试了jQuery的get(),load()和ajax()方法,但无法获取数据。 Here is my code: 这是我的代码:

http://jsfiddle.net/YcprC/ http://jsfiddle.net/YcprC/

  • What's wrong with my code? 我的代码出了什么问题?

  • Is it possible to get data from an ASP.NET web page, then display it on an HTML web page? 是否可以从ASP.NET网页获取数据,然后将其显示在HTML网页上?

  • How to get data from a Div in a web page, then display it in another Div on another web page? 如何从网页中的Div获取数据,然后在另一个网页上的另一个Div中显示?

Thanks in advance... 提前致谢...

You can not get data from other websites because of what is know as Same Origin Policy: 由于所谓的同源策略,您无法从其他网站获取数据:

In computing, the same origin policy is an important security concept for a number of browser-side programming languages, such as JavaScript. 在计算中,相同的源策略是许多浏览器端编程语言(如JavaScript)的重要安全概念。 The policy permits scripts running on pages originating from the same site to access each other's methods and properties with no specific restrictions, but prevents access to most methods and properties across pages on different sites . 该策略允许在源自同一站点的页面上运行的脚本在没有特定限制的情况下访问彼此的方法和属性,但阻止访问不同站点上的页面上的大多数方法和属性 1 1

To workaround that, you should implement JSONP . 要解决此问题,您应该实现JSONP Learn more about it here . 在此了解更多信息。

Or you may also use Yahoo's YQL, see: 或者您也可以使用Yahoo的YQL,请参阅:

You can't do this because of crossdomain security policies. 由于跨域安全策略,您无法执行此操作。 I recommend you load the webpages data with PHP (easy way is file_get_contents , pro way is curl ) and load that php with your jquery. 我建议你用PHP加载网页数据(简单方法是file_get_contents ,亲方式是curl )并用你的jquery加载php。

Same domain - simple. 相同的域 - 简单。 Cross-domain - difficult. 跨域 - 困难。 Not natively supported except in old versions of IE (5.5 and 6) 除旧版IE(5.5和6)外,本机不受支持

If the page being scraped is small enough then you can use the Yahoo Pipes service to fetch the information and pass it back to the app as a JSON string. 如果被抓取的页面足够小,那么您可以使用Yahoo Pipes服务获取信息并将其作为JSON字符串传递回应用程序。 For anything bigger or more complicated use the Google App Engine or run the php fetching of data through a free web Host. 对于任何更大或更复杂的东西,使用Google App Engine或通过免费的网络主机运行php获取数据。

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

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