Javascript 追加不追加内容,而是替换内容

Javascript 追加不追加内容,而是替换内容,javascript,jquery,json,Javascript,Jquery,Json,我正在使用jquery.load函数从服务器加载结果并将其附加到我的html中: $("#content").load('Get/classPosts?class=arts&min=1', function (responseText, textStatus, XMLHttpRequest) { arr = $.parseJSON(responseText); for (i = 1; i < arr.length; i++) { if (arr[i] != null) {

我正在使用jquery
.load
函数从服务器加载结果并将其附加到我的html中:

$("#content").load('Get/classPosts?class=arts&min=1', function (responseText, textStatus, XMLHttpRequest) {
arr = $.parseJSON(responseText);
for (i = 1; i < arr.length; i++) {
    if (arr[i] != null) {
        $('#content').append("<section class='contentpost'><div class='contentimg'><a href='" + arr[i][0] + "'><img src='" + arr[i][2] + "'/></a> </div><div class='contenttitle title'><a href='" + arr[i][0] + "'>" + arr[i][1] + "</a></div></section>").slideDown(100);
    }
}
});
我不知道为什么它在第页上

然而,这可能是一个有点离题的问题,但如果有人也能帮我
。slideDown(100)功能最后,我希望每一个新内容都能以动画的形式滑下,但它也不起作用

谢谢

load()
默认情况下会执行此操作。首先调用
load
时,您告诉它替换
#content
div中的html。您需要使用
GET
POST
检索信息,然后将其附加到
#content

大概是这样的:

[
["93","Title-1","http://stackoverflow.com"],
["92"," Title-2","http://stackoverflow.com"],
["90"," Title-3","http://stackoverflow.com"],
["89"," Title-4","http://stackoverflow.com"],
["89"," Title-5","http://stackoverflow.com"],
null,null,null,null,null]
$.get('Get/classPosts?class=arts&min=1', function (data) {
    if(data.length > 0) {
        arr = $.parseJSON(data);
        var newId;
        for (i = 1; i < arr.length; i++) {
            if (arr[i] != null) {
                // unique id for slidedown to work
                newId = $('.contentpost').length;
                $('#content').append("<section id='contentpost-"+newId+"' class='contentpost'><div class='contentimg'><a href='" + arr[i][0] + "'><img src='" + arr[i][2] + "'/></a> </div><div class='contenttitle title'><a href='" + arr[i][0] + "'>" + arr[i][1] + "</a></div></section>");
                // slide down pointing to the newly added contentposts only
                $('#contentpost-'+newId).slideDown(100);
           }
        }
    }
});
你需要这个,否则幻灯片就不行了。div需要隐藏。

load()
默认情况下会执行此操作。首先调用
load
时,您告诉它替换
#content
div中的html。您需要使用
GET
POST
检索信息,然后将其附加到
#content

大概是这样的:

[
["93","Title-1","http://stackoverflow.com"],
["92"," Title-2","http://stackoverflow.com"],
["90"," Title-3","http://stackoverflow.com"],
["89"," Title-4","http://stackoverflow.com"],
["89"," Title-5","http://stackoverflow.com"],
null,null,null,null,null]
$.get('Get/classPosts?class=arts&min=1', function (data) {
    if(data.length > 0) {
        arr = $.parseJSON(data);
        var newId;
        for (i = 1; i < arr.length; i++) {
            if (arr[i] != null) {
                // unique id for slidedown to work
                newId = $('.contentpost').length;
                $('#content').append("<section id='contentpost-"+newId+"' class='contentpost'><div class='contentimg'><a href='" + arr[i][0] + "'><img src='" + arr[i][2] + "'/></a> </div><div class='contenttitle title'><a href='" + arr[i][0] + "'>" + arr[i][1] + "</a></div></section>");
                // slide down pointing to the newly added contentposts only
                $('#contentpost-'+newId).slideDown(100);
           }
        }
    }
});

你需要这个,否则幻灯片就不行了。div需要隐藏。

因为您正在将请求加载到#内容(可接受的行为)中。您需要使用不同的AJAX请求,可能是get()或getJSON(),因为您正在将请求加载到#内容(可接受的行为)中。您需要使用不同的AJAX请求,可能是get()或getJSON(),非常感谢,完成后工作正常。。顺便说一句,
.slideDown(100)有什么问题吗功能?是的,我现在将更改上面的代码,向您展示并解释它的功能,完成并工作良好。。顺便说一句,
.slideDown(100)有什么问题吗函数?是的,我现在将更改上面的代码,向您展示并解释它