Php 使用ajax显示所有消息通知

Php 使用ajax显示所有消息通知,php,jquery,html,Php,Jquery,Html,我使用AJAX显示消息通知,但问题是如果我同时向特定用户发送两条消息,他只会收到最新的一条。 这是我的_js.js文件: function updatess() { $.getJSON("php/fetch.php", function(data) { $.each(data.result, function(){ var name = this['sender_name']; var message = this['message'];

我使用AJAX显示消息通知,但问题是如果我同时向特定用户发送两条消息,他只会收到最新的一条。 这是我的_js.js文件:

function updatess() {
     $.getJSON("php/fetch.php", function(data) {
       $.each(data.result, function(){
        var name = this['sender_name'];
        var message = this['message'];

       $( '#messages' ).attr( 'id', 'new_msgs' );       
    $('div.from_name').html( name );
    $('div.message').html( message );
   });
 });
}
这是我的索引页:

<div id="msg_holder" style=" overflow-x:scroll ;overflow-y: hidden; position:fixed;height:45px;width:865px;background-color:yellow;bottom:0px; left:144px; ">
<div class="mess_test" style="width:165px; height:35px; background:blue; bottom:0px; left:144px; margin-right: 16px">
<div class="from_name" style="float:left; "></div>
<div class="message" style="float:right;"></div>
</div>

.html()
将重置元素的html,您可能希望改用

将参数指定的内容插入到每个元素的末尾 在匹配元素的集合中

因此,您可以更改:

$('div.from_name').html( name );
$('div.message').html( message );
致:


谢谢,但是如果两条消息来自一个用户,那么这就行了,如果这两条消息来自不同的用户,它会给我类似于消息来源:用户来源:用户来源:用户来源:用户来源:两条消息:嗨消息:你好,我的意思是这两条消息显示在一个窗口中,我想要的是显示在不同的窗口中。
$('div.from_name').append( name );
$('div.message').append( message );