tags:

views:

25

answers:

2

I want to use jquery to read the html of a web page. I use the following

 $.ajax({
        url: page,
        dataType: 'html'
    });

where page is the address of the page.

This works fine if I want to read a page with the same domain as the calling page.

However if I want to read a page from a different domain, it returns blank.

Anyone know how i can read the html from a different domain?

+1  A: 

It's a security feature that disallows this.

You would need to use JSONp to get data across domains.

Jud Stephenson
And you can use JSONp in combination with [ **YQL** ](http://developer.yahoo.com/yql/) to get the HTML from pages on other domains.
Peter Ajtai
+1  A: 

It's simple: You can't. There are tricks to execute javascript code from other domains (JSONP), but generally only if the other side supports it. For HTML, you are out of luck.

The only way you can go is to have a proxy running on your server which redirects requests through your domain.

FRotthowe