На моем веб-сайте есть кнопка «сообщение» в каждом профиле пользователя, поэтому, когда любой пользователь нажимает кнопку «сообщение», он должен переместить его на страницу «сообщения» с помощью ajax.
1-Я не знаю, как взять страницу профиля формы идентификатора пользователя и переместить ее на страницу сообщения с помощью ajax
Если это не первый раз с этим пользователем, следует открыть страницу персональной страницы
ИЗОБРАЖЕНИЕ введите описание изображения здесь СООБЩЕНИЕ BUTON IN PROIFLE USER
введите описание изображения здесь ЧАТ СТРАНИЦА
КНОПКА СООБЩЕНИЯ КОДА НА СТРАНИЦЕ ПРОФИЛЯ
$("#startMessage").click(function()
{
var user_id = $("#user_id").val();
alert(user_id);
$.ajax
({
type:"POST",
url:"<?php echo base_url('Message/index')?>",
data:{'user_id' : user_id},
datatype:'html',
success:function(data)
{
window.location.href="<?php echo base_url('Message/index')?>";
$("#loadMessages").html(data);
}
});
});
КОД ЭТО - СТРАНИЦА КОНТРОЛЛЕРА ПОЛНОЙ СООБЩЕНИЯ, КОГДА ДОЛЖЕН КОД ПОЛУЧИТЬ ИДЕНТИФИКАТОР ПОЛЬЗОВАТЕЛЯ
public function index() //used
{
$user_id =$this->session->userdata('doctor')[0]->user_id;// My Id To Get My User List By My Id
$data["lists"] = $this->Message_model->getMyUserList($user_id);
$this->load->view('front/Message_View',$data);
}
/*
Show Or Get Messge List
*/
public function getMessage() //used
{
$touser = $this->input->post('touser'); // touser Id To Get My User List By touser Id
$data['messages'] = $this->Message_model->getMessage($touser);
foreach($data['messages'] as $message)
{
if ($message->touser == $touser)
{
echo '
<div class="chat-message self">
<div class="chat-message-content-w">
<div class="chat-message-content">'.$message->message.'</div>
</div>
<div class="chat-message-date">'.$message->date_msg.'</div>
<div class="chat-message-avatar"><img alt="" src="https://www.bodywork.sa.com/mohammed/img/face-7.jpg"></div>
</div>
';
}
else {
echo '
<div class="chat-message">
<div class="chat-message-content-w">
<div class="chat-message-content">'.$message->message.'</div>
</div>
<div class="chat-message-avatar"><img alt="" src="https://www.bodywork.sa.com/mohammed/img/face-7.jpg"></div>
<div class="chat-message-date">'.$message->date_msg.'</div>
</div>
';
}
}
}
/*
Send New Messeg
*/
function sendMessage() //used
{
$message = $this->input->post('msg'); // This Data Take From Ajax
$touser = $this->input->post('touser');
// echo $message ,$touser ; die;
// $reservation_id = $this->input->post('reservation_id');
$data= array
(
'message'=>$message,
'date_msg'=>date("Y-m-d H:i:s"),
'touser'=>$touser,
// 'reservation_id'=>$reservation_id,
'status'=>"non",
'chatdeals'=>"non",
'fromuser'=>$this->session->userdata('doctor')[0]->user_id
);
$insert = $this->Message_model->sendMessage($data);
if($insert){
echo 1;
}else{
echo 0;
}
}
СООБЩЕНИЕ КОДА Просмотреть страницу по Ajax
<div class="chat-search">
<!-- serach -->
<div class="element-search"><input placeholder="Search users by name..." type="text"></div>
</div>
<!------------------------- Left Side Start ------------------->
<!-----------------------List user
--------------------------------------------------->
<div class="user-list">
<?php foreach($lists as $list ){ ?>
<div data-touserid="<?php echo $list->user_id ?>" id="<?php echo $list->name ?>" class="user-w">
<!---------------- Evry Thing form This Id IMPORTANT----------------->
<div class="avatar with-status status-green">
<img alt="" src="https://www.bodywork.sa.com/mohammed/img/face-7.jpg"></div>
<div class="user-info">
<div class="user-date">2 days</div>
<div class="user-name"><?php echo $list->name ?></div>
<div class="last-message">They have submitted users...</div>
</div>
</div>
<?php } ?>
</div>
</div>
<!------------------------- Left Side End ------------------->
<div class="full-chat-middle"> <!-- beside the to ueser name put the touer id -->
<div class="chat-head">
</div>
<div class="chat-content-w ps ps--theme_default" data-ps-id="e9e4b066-577f-fc03-9e0c-3979505e77eb">
<div id="loadMessages" class="chat-content">
<!-------------------------------
the design in the controller
/--------------------------------->
</div>
<div class="ps__scrollbar-x-rail" style="left: 0px; bottom: 0px;">
<div class="ps__scrollbar-x" tabindex="0" style="left: 0px; width: 0px;"></div>
</div>
<div class="ps__scrollbar-y-rail" style="top: 0px; right: 0px;">
<div class="ps__scrollbar-y" tabindex="0" style="top: 0px; height: 0px;"></div>
</div>
</div>
<div class="chat-controls">
<div class="chat-input">
<!-------------------------------
messge content value
/--------------------------------->
<input id="message_text" name="message_text" placeholder="Type your message here..." type="text"></div>
<!-------------------------------
add messge script
/--------------------------------->
<div class="chat-btn">
<!-- <a id="sendMessage" class="btn btn-primary btn-sm btn-fill" >Send2</a> -->
</div>
</div>
</div>
СТРАНИЦА AJAX IN VIEW MESSGE
<script>
/*
* Make First Message in page is the first
*
*/
$(document).ready(function(){
$(".user-w:first").trigger("click");
});
/*
* Show User List
*
*/
$(".user-w").click(function()
{
var touser =$(this).data('touserid');
//$(this).attr("touserid"); // touser Id To Get My User List By touser Id
var touserName = $(this).attr("id"); // touser Id To Get My User List By touser Id
alert(touser);
alert(touserName);
$.ajax
({
type:"POST",
url:"<?php echo base_url('Message/getMessage/')?>",
data:{'touser' : touser},
datatype:'html',
success:function(data)
{
$("#loadMessages").html(data); // refrech the chat to get the news by ajax real time
//alert ("yub");
var button = '<button type="button" onclick="sendMessage('+touser+')" class="btn btn-info send_chat">Send</button>';
$(".chat-btn").html(button); // button to send messge touser by ajax with the touser id
var Head = ' <div id="user-info" class="user-info" "><span>To:</span><a href="<?php echo base_url('Profile/getUserById/')?>'+touser+'">'+touserName+'</a></div>';
$(".chat-head").html(Head);
}
});
});
/*
* Send New Messeg
*
*/
function sendMessage(touser)
{
//alert("test");
//alert(user_id);
var msg = $("#message_text").val();
var touser = touser;
// alert(touser);
//alert(msg);
//var reservation_id = $("#reservation_id").val();
if(!msg || msg.length == 0)
{
alert("enter a message");
}
else
{
$.ajax
({
type:"POST",
url:"<?php echo base_url('Message/sendMessage')?>",
// data:{'msg' : msg, 'touser' : touser, 'reservation_id' :
reservation_id},
data:{'msg' : msg, 'touser' : touser},
datatype:'text',
// Page.Server.ScriptTimeout = 300;
success:function(data)
{
if(data == 1)
{
//$("#loadMessages").load();
$("#message_text").val("");
$(".user-w[id='"+ touser +"']").trigger("click");
}
else
{
alert("noo eroor chat message") ;
}
},
});
//return false;
}
} // End Send Message Function
</script>