对话列表系统


Conversation List System

我实际上正在构建一个对话系统,我有一个页面显示用户的所有对话,并允许他选择要回复的对话,总体设计如下:

我在这里上传了一般结构的图像:

http://tinypic.com/r/2myvhno/8

所以它就像对话列出一列,而对话本身占据右列。当用户单击对话时,右侧的正确对话会弹出,所以我认为这将需要一些 ajax 在发送 php 代码以查询数据库中的对话时不刷新页面基于id。

所以一般功能的工作原理是这样的:

  1. 用户选择对话,对话显示在右侧。
  2. 用户选择另一个对话,右侧的对话发生变化。

我对 php 和查询数据库很好,无法获取对话,但不熟悉允许用户选择对话并显示正确对话所需的 ajax/javascript 和 html。

多谢。

我假设您是通过"#user_id"获得对话的。 并执行以下操作

你需要这样的东西,1(给右一个ID,说"#right">

2(包含必要的jQuery库后,获取特定用户的点击事件

$(document).on("click", "#user_id", function(){
    var user_id = $(this).attr('id_of_particular_user'); //you are getting the user id here
     var request = $.ajax({
                        url: "your_path_to_a_php_file_that_gives_you_the_conversation.php",
                        type: "POST",
                        data: { user_id: user_id },
                        beforeSend: function(){
                            self.html("loading please wait...");
                        }
                    });
    //WHEN SUCCESS
    request.success(function( data ) {
        $("#right").html(data); //this line will replace the right with echoed content from php file
    });
});
  1. your_path_to_a_php_file_that_gives_you_the_conversation.php在这里将对话作为 html 代码回显,如echo "<li>conversation line</li>";