Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

I tried jQuery's get(), load(), and ajax() methods, but unable to get the data. Here is my code:

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?

  • How to get data from a Div in a web page, then display it in another Div on another web page?

Thanks in advance...

like image 283
Bayu Avatar asked Feb 22 '23 10:02

Bayu


2 Answers

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. 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

To workaround that, you should implement JSONP. Learn more about it here.

Or you may also use Yahoo's YQL, see:

  • Quick Tip: Cross Domain AJAX Request with YQL and jQuery
like image 88
Sarfraz Avatar answered Feb 23 '23 23:02

Sarfraz


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.

like image 29
19greg96 Avatar answered Feb 23 '23 23:02

19greg96