简体   繁体   English

JQuery - 使用.innerHTML附加而不是替换内容?

[英]JQuery - append rather than replace content using .innerHTML?

Below is a function that retrieves a users older wallposts, 16 at a time, and appends each chunk of 16 to the end of the current list in the div called "sw1". 下面是一个函数,它一次检索16个用户较旧的wallposts,并将每个16块附加到名为“sw1”的div中当前列表的末尾。

It works fine, except in the case where there is currently a wallpost that contains a video/embedded object that is currently in the process of playing. 它工作正常,除了当前有一个包含当前正在播放的视频/嵌入对象的wallpost的情况。 When we click on the button that calls the function below during the playback of an object in sw1, the below function seems to cause the entire content of sw1 to be removed, and then re-dumped. 当我们在sw1中播放对象期间单击调用下面函数的按钮时,下面的函数似乎会导致sw1的整个内容被删除,然后重新转储。

Is it possible to modify the function below so that it merely appends new data to the end of sw1, rather than replacing the entire contents, killing any objects that are currently playing?? 是否可以修改下面的函数,以便它只是将新数据附加到sw1的末尾,而不是替换整个内容,杀死当前正在播放的任何对象?

function fetch_older_wallposts(u,lim){
var xhr = getXMLHttpRequest();

xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

//document.getElementById( 'sw1' ).innerHTML.append( xhr.responseText );
document.getElementById( 'sw1' ).innerHTML += xhr.responseText;
}else{
document.getElementById( 'oaps_loading' ).innerHTML = 'loading';
}
};

xhr.open("POST", "script.php?u="+u+"&lim="+lim, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(null);
}

Any sort of assistance or guidance appreciated guys.... 任何形式的帮助或指导都赞赏...

Thanks for all the usefull comments guys! 感谢所有有用的评论家伙!

If you are going to use jQuery, why mix and match styles, use jQuery all the way: 如果你打算使用jQuery,为什么混合和匹配样式,一直使用jQuery:

function fetch_older_wallposts(u,lim){
    $('#oaps_loading').html('loading');
    $.ajax({url: 'script.php', data: { u: u, lim: lim}, type: 'POST', 
        success: function(data) {
            $('#sw1').append(data);
        });
}

Call $('#sw1').append(xhr.responseText); 调用$('#sw1').append(xhr.responseText); .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM