[英]Load content from external page into another page using Ajax/jQuery
Is there a way to do this? 有没有办法做到这一点?
page1.php --has page1.php - 有
<div id="main">
<div id="content">hello</div>
</div>
index.php --has index.php - 有
<div id="main">
</div>
Can I somehow grab the data from page1.php inside of the content
div and load it into the main
div in my index.php? 我可以以某种方式从
content
div中的page1.php中获取数据并将其加载到我的index.php中的main
div中吗?
I have done this with the code provided at css-tricks url: http://css-tricks.com/examples/DynamicPage/ 我已经使用css-tricks网址提供的代码完成了这项工作: http : //css-tricks.com/examples/DynamicPage/
But this uses hash change events. 但这会使用哈希更改事件。 I don't want to use the hash feature, just the load content feature, but I can't seem to isolate the code for that because I think it's built into the bbq hashchange plugin.
我不想使用散列特性,只是加载内容功能,但我似乎无法隔离代码,因为我认为它内置于bbq hashchange插件中。
Is there an Ajax way of doing it? 有Ajax方式吗?
Something like 就像是
$(selector).find('#main').load('#content');
Just put a filtering selector after the URL in .load
's first argument: 只需在
.load
的第一个参数中的URL后面添加一个过滤选择器:
$(document).ready(function() {
$("#main").load('page1.php #content');
});
That will inject the #main div in the current page with the contents of #content from page1.php. 这将在当前页面中注入#main div,其中包含来自page1.php的#content内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.