2014-11-23 89 views
0

下面的代碼是自動添加註釋而不刷新的代碼。如何使用DESC訂購

當它運行時,添加div的ASC命令,我希望它通過DESC命令div,這裏的任何人都有任何想法我該怎麼做?

謝謝。

$("#send").click(function() { 
    $.ajax({ 
     type: "POST", 
     url: "http://localhost/index.php?/main/add_comment", 
     data: { 
      textbox: $("#textbox").val() 
     }, 
     dataType: "text", 
     cache: false, 
     success: function(data) { 
      document.getElementById('comments').innerHTML += "<div class=\"col-lg-6\">" + 
       "<div class=\"well well-sm\">" + 
       "<div class=\"col-md-2 comment-img\">" + 
       "<img src=\"/img/avatar_img.png\"> " + 
       "</div>" + 
       "<div class=\"col-md-10\">" + 
       "<p class=\"text-left\">admin said:<pre>" + data + "</pre></p>" + 
       "<p class=\"text-right timeago\">Posted 0 secounds ago.</p>" + 
       "</div>" + 
       "<div class=\"clearfix\">" + 
       "</div>" + 
       "</div>" + 
       "</div>"; 

     } 
    }); 
    return false; 
}); 
+0

更換document.getElementById('comments').innerHTML我不明白......你剛剛發佈的代碼替換爲數據的評論div返回。我沒有看到有很多評論。如果你想讓你的評論在其他評論之前顯示,請使用$('#comments')。prepend('YOUR HTML HERE'); – 2014-11-23 00:39:02

回答

0

通過document.getElementById('comments').insertAdjacentHTML("afterbegin", theHTML);

success: function (data) { 
    var HTMLtext = "<div class=\"col-lg-6\">" + 
     "<div class=\"well well-sm\">" + 
     "<div class=\"col-md-2 comment-img\">" + 
     "<img src=\"/img/avatar_img.png\"> " + 
     "</div>" + 
     "<div class=\"col-md-10\">" + 
     "<p class=\"text-left\">admin said:<pre>" + data + "</pre></p>" + 
     "<p class=\"text-right timeago\">Posted 0 secounds ago.</p>" + 
     "</div>" + 
     "<div class=\"clearfix\">" + 
     "</div>" + 
     "</div>" + 
     "</div>"; 
     document.getElementById('comments').insertAdjacentHTML("afterbegin",HTMLtext); 
}