jQuery load&再次加载功能

时间:2012-03-14 00:25:00

标签: jquery html

我正在使用jQuery加载函数将url加载到div中。一旦成功加载,我想在上一个加载的内容下直接加载另一个URL。

我的HTML

<div id=content></div> 

我的jquery

$('#content').load('first_content.php', null, function() {
    $('#content').append().load('second_content.php');
});

问题是第二个加载的内容完全取代了第一个加载的内容。

如何在加载first_content后附加内容,以便它显示在下面?

感谢

2 个答案:

答案 0 :(得分:3)

实际上你正在替换#content内容,尝试在加载第二个内容的情况下附加一个新的div。

$('#content').load('first_content.php', null, function() {
    $('#content').append($('<div/>').load('second_content.php'));
});

答案 1 :(得分:0)

加载第一个块。完成后,创建一个div并将第二个块加载到该div中。当那个完成时将div附加到内容区域。

$('#content').load('first_content.php', null, function() {
    $("<div>").load('second_content.php', function() {
        $(this).appendTo("#content");
    });
});