繁体   English   中英

使用Ajax / jQuery将外部页面中的内容加载到另一个页面

[英]Load content from external page into another page using Ajax/jQuery

有没有办法做到这一点?

page1.php - 有

<div id="main">
   <div id="content">hello</div>
</div>

index.php - 有

<div id="main">
</div>

我可以以某种方式从content div中的page1.php中获取数据并将其加载到我的index.php中的main div中吗?

我已经使用css-tricks网址提供的代码完成了这项工作: http//css-tricks.com/examples/DynamicPage/

但这会使用哈希更改事件。 我不想使用散列特性,只是加载内容功能,但我似乎无法隔离代码,因为我认为它内置于bbq hashchange插件中。

有Ajax方式吗?

就像是

$(selector).find('#main').load('#content');

只需在.load的第一个参数中的URL后面添加一个过滤选择器:

$(document).ready(function() {
    $("#main").load('page1.php #content');
});

这将在当前页面中注入#main div,其中包含来自page1.php的#content内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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