Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
set_flashdata not working when reloading using javascript

I'm working on a project using codeigniter 3 to send data to a function using POST fetch where it would set a flashdata in the end. but the flashdata doesn't show when I reloaded the page using javascript. why is that?

this is my code:

HTML & 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
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda