【问题标题】:Load content from external page into another page using Ajax/jQuery使用 Ajax/jQuery 将外部页面的内容加载到另一个页面
【发布时间】:2011-06-01 09:42:21
【问题描述】:

有没有办法做到这一点?

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 url 提供的代码:http://css-tricks.com/examples/DynamicPage/

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

有没有一种 Ajax 方法?

类似

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

【问题讨论】:

    标签: javascript jquery ajax


    【解决方案1】:

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

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

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

    【讨论】:

    • 4 小时后!上帝保佑你这个答案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多