标签内容会在点击时显示,但随后会消失。这是我正在研究的聊天模块。我在我的后端使用codeigniter。谢谢你的帮助!
这是我的JS:
function tabFunction(clickedid){
$.ajax({
url: base_url + "Admin/get_message_per_customer",
data: {message: clickedid},
method: "GET",
success: function(data) {
$('#v-pills-tabContent').html(data);
}
});
}
这是我的控制器(当您单击选项卡时,它应显示特定于您单击的名称的消息):
public function get_customer_messages(){
$this->load->model('Crud_model');
$data = $this->Crud_model->chat_admin_customer();
foreach ($data as $row):
if($row->chat_exists == 1)
{
echo "<a class='nav-link' id='";
echo $row->customer_id;
echo "'onclick='tabFunction(this.id)' data-toggle='pill' href='#v-pills-home' role='tab' aria-controls='v-pills-home' aria-selected='true'";
echo "data-id=";
echo $row->customer_id;
echo ">";
echo $row->first_name;
echo " ";
echo $row->last_name;
echo "</a> <br>";
}
endforeach;
die;
}
public function get_message_per_customer(){
$customer_id = $this->input->get('message');
$this->load->model('Crud_model');
$data = $this->Crud_model->chat_customer($customer_id);
echo "<div class='tab-pane fade show' id='v-pills-home' role='tabpanel' aria-labelledby='v-pills-home-tab'>";
foreach ($data as $row):
if($row->customer_id == NULL && $row->admin_id == 0){
echo "";
}elseif($row->customer_id != NULL && $row->admin_id == 0 ){
$message = $row->message;
echo "<div class='answer left'>
<div class='avatar'>
</div>
<div class='name'>";
echo "</div>";
print_r($message);
echo "</div>";
}
if($row->admin_id == 0){
echo "";
}
elseif($row->admin_id == 1){
echo "<div class='answer right'>
<div class='avatar'>
<img src=".base_url("assets/img/person.png")." alt='User name'>
</div>
<div class='name'>Gomoto(Customer Service)</div>";
$message_admin = $row->message;
print_r($message_admin);
echo "</div>";
}
endforeach;
echo "</div>";
}