I cannot recover $_SESSION with ajax and codeigniter

Asked

Viewed 109 times

0

I’m having trouble recovering a $_SESSION using php native Session with ajax in codeigniter, because when I try to verify the data informUndefined. follows the code, since thanks to all.

controller login

if($user->cod_user == 1)
    {


        $_SESSION['admin'] = $user->name;

        echo "<script>location.href='admin';</script>";

    }
    else if($user->cod_user == 2)
    {
        $_SESSION['admin'] = $user->name;

        echo "<script>location.href='vendedor';</script>";
    }

in the view you receive (admin or seller) arrives as Undefined

I suspect the way I’m doing the redirect with javascript, because in this msm controller I can visualize the normal.

ajax requisition

$(function(){

        $('#gestao').slideDown('slow');

        // efetua login no sistema
        $('#bt_login').click(function(){

            $.post('<?php echo site_url()?>/Login', $('#form_login').serialize())
            .done(function(data){
                $('#msg_erro').html(data);


            });

        });
    });
  • If the data is coming you have no reason why not store, check if the session has been flattened and debug the user object with var_dump()

  • this part of the object this tranquil Elipe because I’ve debugged returning in ajax. this part q ta sinister na hr q i do the redirect with javascript but it’s not coming in view :/

  • and in the __Construct controller I’ve already put $this->load->library('Session');

  • weird, make sure you also posted in admin/seller views

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.