简体   繁体   English

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

[英]jQuery().append is working but .html is not working on ajax call

I'm using WordPress.我正在使用 WordPress。 After getting response I'm using jQuery().append(response).Its working fine.得到响应后,我正在使用 jQuery().append(response)。它工作正常。 Problem is that it is generating multiple div.That's why I need to use html or innerHtml.But it is not working.问题是它正在生成多个 div。这就是为什么我需要使用 html 或 innerHtml。但它不起作用。 Though I'm getting response back from server.虽然我从服务器得到响应。

        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);

You should wrap the response within brackets.您应该将响应括在括号内。

Ex:前任:

jQuery("#show-chat-div-text").html(response);

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

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