• 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

#2
[eluser]InsiteFX[/eluser]
Code:
redirect('controller/method', 'refresh');

#3
[eluser]slyover3[/eluser]
[quote author="InsiteFX" date="1363190788"]
Code:
redirect('controller/method', 'refresh');
[/quote]

thank you for reply but, redirect work with controller/view, no method and if I using redirect is not ajax, but a simple refresh of the page.


#4
[eluser]TheFuzzy0ne[/eluser]
I'm not sure I understand you, but to refresh the page using Javascript, you would do something like:

Code:
document.location.reload(true)

#5
[eluser]slyover3[/eluser]
I don't want refresh page, i would like using ajax for reload my message without refresh the page. Thank you Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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