Estoy trabajando en un proyecto usando codeigniter 3 para enviar datos a una función usando POST fetch donde establecería un flashdata al final. pero los datos flash no se muestran cuando recargué la página usando javascript. ¿porqué es eso?
este es mi código:
HTML y JavaScript
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <?php pre($this->session->keep_flashdata('asd') ?: 'empty');?> <form method="post" action="" id="form1"> <input type="hidden" id="csrf" name="<?=$this->data['csrf_name'];?>" value="<?=$this->data['csrf'];?>" /> <input type="text" name="input1" /> <input type="submit" id="btnSubmit" value="Kirim"> </form> <script> const btnSubmit = document.querySelector('#btnSubmit'); btnSubmit.addEventListener('click', function(e) { e.preventDefault(); const myform = document.querySelector('#form1'); let fd = new FormData(myform); fetch('/test/test11', { method: 'POST', body: fd }) .then(response => response.json()) .then(res => { console.log('res', res); if (res.status) { window.location.href = window.location.href; } }) }); </script> </body> </html>PHP
public function test11($param = '') { $this->load->library('My_validations'); $conf_uploader = $this->config->load('uploader_settings', true); if ($this->input->server('REQUEST_METHOD') == 'POST') { $this->session->set_flashdata('asd', 'qwerty'); $response = [ 'status' => 1, 'msg' => 'asdasd', ]; echo json_encode($response); return; } $this->data['conf_uploader'] = $conf_uploader; $this->load->view('myform', $this->data); } // end public function test11