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

有没有办法做到这一点?

page1.php – 有

hello

index.php – 有

 

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

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

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

有Ajax方式吗?

就像是

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

只需在.load的第一个参数中的URL之后放置一个过滤选择器:

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

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