开发者

read pages html with jquery

开发者 https://www.devze.com 2023-01-18 23:31 出处:网络
I want to use jquery to read the html of a web page. I use the following $.ajax({ url: page, dataType: \'html\'

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

 $.ajax({
        url: page,
        dataType: 'html'
    });
开发者_StackOverflow中文版

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?


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.


It's a security feature that disallows this.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消