[eluser]slyover3[/eluser]
Hi guys,
I have a big problem, are days that i trying to resolve this problem but I don't know as do.
I want to refresh my message when I insert into database a message. For insert with ajax it work perfect.
Controller:
Code:
function index(){
$this->load->library('form_validation');
$this->load->view('head');
//id session
$id_user = $this->session->userdata('user_id');
//id profile
$id_profile = $this->uri->segment(3);
// messagge
$data['mex'] = $this->reload();
$this->load->view('profile_view.php',$data);
if($mex = $this->input->post('message') != NULL) {
$this->user_model->insert_mex($mex,$id_user);
}
($dat = $this->input->post('data') == true) {
$data['mex'] = $this->reload();
}
}
function reload() {
$id_user = $this->session->userdata('user_id');
$this->load->model('user_model');
$str = $this->user_model->reload_model($id_user);
return $str;
}
Model "user_model":
Code:
function reload_model($user_id) {
$this->db->select('*');
$this->db->from('messages');
$this->db->where('id_user',$user_id);
$this->db->limit('10');
$this->db->order_by('id_mex',"desc");
$querys = $this->db->get();
return $querys -> result();
}
function insert_mexl($mex,$id_user) {
$dati = array(
'message' => $mex,
'id_user' => $id_user
);
$this->db->insert('messages',$dati);
return true;
}
View:
Code:
[removed]
$(document).ready(function(){
// insert message profile
$(".share").click(function(){
var message = $(".comment").val();
var url = "";
$.ajax({
url: url,
type: 'POST',
data: "message=" + message,
success: function(msg) {
$('.comment').val("");
reload();
}
});
return false;
});
function reload() {
var data = true;
var url = "";
$.ajax({
url: url,
type: 'POST',
data: "data=" + data,
success: function(msg) {
$('.comment').val("");
}
});
return false;
}
});
[removed]
<textarea class="comment" placeholder="Write a comment..." name="message"></textarea>
<button class="btn-primary share">Share</button>
<?php foreach ($mex as $mel): ?>
<div class="image"><?php echo $mel->image ?></div>
<div class="message"><?php echo $mel->message ?></div>
<div class="like"><?php echo $mel->like ?></div>
<?php endforeach; ?>
please help me