I want to reload page after submitting data, but I got some problem with that, i've tried several ways but it doesn't work. here's my code :
here's the ajax :
$('#form-tambah-posisi').submit(function(e) {
var data = $(this).serialize();
$.ajax({
method: 'POST',
url: '<?php echo base_url('Posisi/prosesTambah'); ?>',
data: data
})
.done(function(data) {
var out = jQuery.parseJSON(data);
tampilPosisi();
if (out.status == 'form') {
$('.form-msg').html(out.msg);
effect_msg_form();
location.reload();
} else {
document.getElementById("form-tambah-posisi").reset();
$('#tambah-posisi').modal('hide');
$('.msg').html(out.msg);
effect_msg();
}
})
e.preventDefault();
});
here's the controller :
public function prosesTambah() {
$this->form_validation->set_rules('tgl_date', 'Date', 'trim|required');
$data = $this->input->post();
if ($this->form_validation->run() == TRUE) {
$result = $this->M_posisi->insert($data);
if ($result > 0) {
$out['status'] = '';
$out['msg'] = show_succ_msg('Add Success!', '20px');
} else {
$out['status'] = '';
$out['msg'] = show_err_msg('Add Failed!', '20px');
}
} else {
$out['status'] = 'form';
$out['msg'] = show_err_msg(validation_errors());
}
echo json_encode($out);
}
Looking forward for solution. thank's.
In PHP you can simply use this :
echo "<meta http-equiv='refresh' content='0'>";
where you want page reload
You can send headers to a customer.
header('Location: http://www.example.com/');
you can try this
location.reload(true);
you can force to reload the page from the server by setting the forceGet parameter to true. check it here