簡體   English   中英

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

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

我正在使用 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);

您應該將響應括在括號內。

前任:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM