我正在进行ajax调用并替换div类中的响应。在第一次ajax调用时,响应在类中被正确替换,但第二次我从响应中获取数据但响应没有替换类中的数据。
我正在尝试以下方式。
$(document).on('click', '#approveallusers', function(){
var checked_ids = []
$("#UserList").find('input[type=checkbox]').each(function () {
var $this = $(this);
if($this.is(":checked") && $this.hasClass('selectbox')){
checked_ids.push($this.attr("userid"));
}
});
$.ajax({
url : '/approve-website-users',
method : 'POST',
data : JSON.stringify({'checked_ids':checked_ids}),
contentType : "application/json",
success : function(data) {
if(data.status == 'success') {
alert(data.res)
$('.users').replaceWith(data.res);
}
}
});
})
这里data.res
是一个html元素,它是从服务器端呈现的。
感谢..
答案 0 :(得分:1)
.replaceWith
将替换包含html标记的div,因此不会有任何类用户。
有关详情,请参阅此处: http://api.jquery.com/replacewith/#replaceWith-function
您可能需要.innerHTML
或.html
点击此处:http://api.jquery.com/html/#html-htmlString