从一个页面加载div内容并将其显示到另一页面 [英] Load div content from one page and show it to another
问题描述
小时数,我试图从一个页面加载div内容并将其显示给另一页面. 例如:
Couple of hours I am trying to load a div content from one page and show it to another. for example:
我们有此Wikipedia页面.我想使用id="mw-content-text"
获取div的内容,并将其显示在具有id="result"
元素的页面上.
We have this wikipedia page. I want to get the content of the div with id="mw-content-text"
and show it to my page that has element with id="result"
.
有没有办法仅使用javascript/jquery?
Is there a way to do it only with javascript/jquery?
推荐答案
First download the JS file https://github.com/padolsey/jQuery-Plugins/blob/master/cross-domain-ajax/jquery.xdomainajax.js and include the js file in your page. Below is the function that I used to load the external page.
function test () {
$.ajax({
url: 'http://external_site.com',
type: 'GET',
success: function(res) {
var content = $(res.responseText).text();
alert(content);
}
});
}
这对于我从外部网站获取内容很有帮助.
This worked for me getting content from external site.
Reference
这篇关于从一个页面加载div内容并将其显示到另一页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!