mercredi 21 septembre 2016

Trouble with getting cookies Laravel

Is it possible to read cookies in laravel 5.3 from ajax function?

I set cookies from ajax:

Cookie::queue('test', $test, 900)

Is all ok, in index controller there is no problem to see the result:

$data = Cookie::get();
debug($data);

result:

Array
(
    [XSRF-TOKEN] => m84KsCPi9C68OLY21arp1Ha9qltPsKNNXKBfnxJ6
    [laravel_session] => e656c82742a87563f1b3835035ea5fd877380fb1
    [test] => gGTBoeXzcxdYnmjv2Nkt
)

But when i tried to run exactly the same command in another ajax function, the result is:

Array
(
    [test] => 
    [XSRF-TOKEN] => m84KsCPi9C68OLY21arp1Ha9qltPsKNNXKBfnxJ6
    [laravel_session] => e656c82742a87563f1b3835035ea5fd877380fb1
)

My ajax javascript call:

$.ajax({
    headers: {
         'X-CSRF-TOKEN': here_is_generated_token
    },
    method: form.attr('method'),
    dataType: 'json',
    url: form.attr('action'),
    data: { 
        form_data: form.serialize() 
    }
 }).done(function( msg ) {
     console.log(msg);
 });

I tryed to do the same with hidden input , the is no progress.

Why i can set, but can't read? Thank you very much



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire