我目前正在使用 Ajax 来更新信息源。 Ajax 应该添加到当前结果列表而不是替换现有结果。
到目前为止,我已经创建了从数据库获取数据所需的 Ajax,但在回调函数中我使用以下回调函数
fetchPosts.onreadystatechange = function() {
if(fetchPosts.readyState === 4) {
$("#resultfeed").html(fetchPosts.responseText);
}
}
显然,在回调函数中使用 $("#resultfeed").html(fetchPosts.responseText);
意味着页面上任何先前的结果都会被覆盖。如何更改此设置以便将结果添加到当前结果列表中?
最佳答案
使用附加或前置
$("#resultfeed").append(fetchPosts.responseText); // Adds at the end
$("#resultfeed").prepend(fetchPosts.responseText); // Adds at the top
关于javascript - 什么是 $ ("#myDiv").html(myResult); 更好的替代品在这种情况下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39471104/