Hello
I think it should be fairly easy, I simply can not find an answer for it.
I am using a Codeigniter for a simple CRUD application. It displays the result in table. What I did, was to use jQuery .ajax
to submit the form. It works (almost) perfectly.
I am able to submit a form without reload but the results are not shown unless I reload the page. For now I use location.reload();
but it does not make sense, after all my intentions were not to reload the page.
I know I should echo the data back, but have no idea how to do it with CI.
Some insides:
jQuery part
$("#add_form").submit(function(e) {
e.preventDefault();
var dataString = $("#add_form").serialize();
$.ajax({
type: "POST",
url: "add",
data: dataString,
success: function() {
$("#lightbox").fadeIn(300).delay(1000).fadeOut(300);
$("#notification-box").show();
$("#notification-box").html('<p>Saving</p>');
$("#addrow").hide();
location.reload();
}
});
});
controller part
function add()
{
if(!$this->ion_auth->logged_in())
{
redirect('auth/login', 'refresh');
}else
{
// User ID
$user_data = $this->ion_auth->get_user();
$user = $user_data->id;
// Prepare post data
$data['user'] = $user;
$data['cdate'] = date('Y-m-d');
$data['ctime'] = date('H:i:s');
$data['mdate'] = date('Y-m-d');
$data['mtime'] = date('H:i:s');
$pair_value = $this->input->post('vpair');
if(empty($pair_value))
{
$data['pair'] = "no pair";
}else
{
$data['pair'] = $pair_value;
}
$reason_value = $this->input->post('reason');
if(empty($reason_value))
{
$data['reason'] = "";
}else
{
$data['reason'] = $reason_value;
}
$comment_value = $this->input->post('comment');
if(empty($comment_value))
{
$data['comment'] = "";
}else
{
$data['comment'] = $comment_value;
}
// Insert_data
$this->journal_model->add_trade($data);
}
}
Help? Anyone?
Cheers,
/J