• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI + AJAX result Refresh message

#1
[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>
&lt;?php foreach ($mex as $mel): ?&gt;
<div class="image">&lt;?php  echo $mel->image ?&gt;</div>
<div class="message">&lt;?php echo $mel->message ?&gt;</div>
<div class="like">&lt;?php echo $mel->like ?&gt;</div>
&lt;?php endforeach; ?&gt;

please help me


Messages In This Thread
CI + AJAX result Refresh message - by El Forum - 03-13-2013, 08:14 AM
CI + AJAX result Refresh message - by El Forum - 03-13-2013, 09:06 AM
CI + AJAX result Refresh message - by El Forum - 03-13-2013, 09:49 AM
CI + AJAX result Refresh message - by El Forum - 03-14-2013, 12:27 AM
CI + AJAX result Refresh message - by El Forum - 03-14-2013, 05:42 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.