Javascript jQuery().append正在工作,但是.html在ajax调用上不工作

Javascript jQuery().append正在工作,但是.html在ajax调用上不工作,javascript,jquery,ajax,wordpress,Javascript,Jquery,Ajax,Wordpress,我在用WordPress。在得到响应后,我使用jQuery().append(response)。工作正常。问题是它正在生成多个div。这就是为什么我需要使用html或innerHtml。但它不起作用。虽然我从服务器上得到了响应 function get_chat_history() { //var doc = document.getElementById("show-chat-div-text"); docu

我在用WordPress。在得到响应后,我使用jQuery().append(response)。工作正常。问题是它正在生成多个div。这就是为什么我需要使用html或innerHtml。但它不起作用。虽然我从服务器上得到了响应

        function get_chat_history() {
            //var doc = document.getElementById("show-chat-div-text");
            document.getElementById("show-chat-div-text").lastElementChild;
            var id_of_incoming_chat_user=document.getElementById("show-chat-div-[![enter image description here][1]][1]text").lastElementChild;
            var id_incoming_chat_user;
            if (id_of_incoming_chat_user!=null) {
             id_incoming_chat_user= id_of_incoming_chat_user.getAttribute('class');

            }
            else (id_of_incoming_chat_user===null)
            {

                id_incoming_chat_user=document.getElementById("show-chat-div-text").getElementsByTagName("Div")[0].getAttribute('class');


            }
            if(id_incoming_chat_user==="user-hide")
            {

                id_incoming_chat_user=document.getElementById("show-chat-div-text").getElementsByTagName("Div")[1].getAttribute('class');

            }


            cur_user = '<?php echo get_current_user_id() ;?>';
            var message = document.getElementById("myInput").value;
            var listitem="";
            var postdata = {action: "navid_history_ajax_call",
                            param_user_to_chat: id_incoming_chat_user,
                            param_main_user:cur_user,
                            message:message                                                     
                            };
            jQuery.post(ajaxurl, postdata, function (response) {

                            //jQuery("#show-chat-div-text").html=response;//not working
                          //  jQuery("#show-chat-div-text").append(response);//Working 
                                                
                            console.log(response);
                            chatBox.scrollTop = chatBox.scrollHeight;
                                 });                 

        }
        setInterval(get_chat_history, 5000);
函数get\u chat\u history(){
//var doc=document.getElementById(“显示聊天室div文本”);
document.getElementById(“show chat div text”).lastElementChild;
var id_of_incoming_chat_user=document.getElementById(“show chat div-[![enter image description here][1]][1]text”).lastElementChild;
var id \传入\聊天\用户;
if(传入聊天用户的id=null){
id_incoming_chat_user=id_of_incoming_chat_user.getAttribute('class');
}
else(传入聊天用户的id===null)
{
id\u incoming\u chat\u user=document.getElementById(“显示聊天div文本”).getElementsByTagName(“div”)[0]。getAttribute(“类”);
}
如果(id\u传入\u聊天\u用户==“用户隐藏”)
{
id\u incoming\u chat\u user=document.getElementById(“显示聊天div文本”).getElementsByTagName(“div”)[1].getAttribute(“类”);
}
cur_user='';
var message=document.getElementById(“myInput”).value;
var listitem=“”;
var postdata={action:“navid_history_ajax_call”,
param_user_to_chat:id_incoming_chat_user,
参数主用户:当前用户,
信息:信息
};
post(ajaxurl、postdata、函数(响应){
//jQuery(#show chat div text”).html=response;//不工作
//jQuery(#show chat div text”).append(response);//工作
控制台日志(响应);
chatBox.scrollTop=chatBox.scrollHeight;
});                 
}
设置间隔(获取聊天记录,5000);

您应该将响应用括号括起来

例:


Try:
jQuery(“#show chat div text”).html(响应)?您好,这是jQuery(#show chat div text”).html=response应该是
jQuery(#show chat div text”).html(响应)jQuery(“#show chat div text”).empty()
然后使用
append()
或者使用
jQuery(“#show chat div text”).html(”
然后使用
append()
@swati使用jQuery(#show chat div text”).empty()然后append()。@share谢谢。看来这就是问题所在。
jQuery("#show-chat-div-text").html(response);