简体   繁体   中英

Loading a div from a different domain

I'm hosting a page on an sharepoint site, and need to pull content from multiple other pages. The content I need is on a different domain in a div, so I cannot use an iFrame. I've tried the following code with JQuery attempting to load the stcakoverflow container div from the landing page, but this doesn't seem to work. I'm assuming this is due to different origin policy:

<script>
    $(document).ready(function() {
       $('#LoadMe').load("http://www.stackoverflow.com#container");
    });
 </script>

Is there a way to do this through Jquery, or is there an alternate solution?

If you can encode the other domain's data in JSON, you can do cross-domain requests using JSONP requests . This of course requires that you are able to change or request a different type of encoding from the other domains so if that's not under your control this approach is not possible.

No, you can't just load up another page (or a piece of it) like that with Javascript. You would need to do it on the backend via PHP, .NET, or some other server-side scripting language, then pass the results to your page.

您还可以获取所需页面的内容,并使用regexp进行解析,或者如上述Nate B所述,编写某种类型的代码,例如Rss Feed,使用json传递内容,创建一些Web服务等

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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