lundi 30 novembre 2015

Session::flash not working in ajax laravel 5

I have action named getuser which is called by ajax.

Here is my ajax

var $_token = $('#token').val();
var BASE = "{{ URL::to('/') }}";
$.ajax({
        url: BASE + "/admin/user/test",
        type: 'POST',
        data: {type:type, id:id},
        headers: { 'X-XSRF-TOKEN' : $_token },
        success: function(data){
            // Success...
            console.log(data);
            location.reload();
        }
    }); 

Controller action,

public function getuser()
{
    Session::flash('message', 'This is a message!'); 
    Session::flash('alert-class', 'alert-danger');
    exit;
}

And into view i have code like this,

@if(Session::has('message'))
    <p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p>
@endif

But not working for me. Any suggestion?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire