mardi 22 septembre 2015

TokenMismatchException In Laravel 5 AJAX

I am trying to create a AJAX call in Laravel 5. But I am geting TokenMismatchException but don't know why.

My AJAX code is -

$(document).ready(function()
{
    $("#send").click(function()
    {
        $.ajax({
                    headers: { 'csrftoken' : '{{ csrf_token() }}' },
                    type:   'POST',
                    url:    'add_question',
                    data:   { 
                                'webinar_id'        : 1,
                                'email_id'          : "any@email.com",
                                'question'          : $('#question_to_ask').val(),
                                'answer'            : "",
                                'panelist_id'       : 1,
                                'public'            : 1
                            },
                    success: function(data)
                    {
                        $("ul#question_list").prepend(data);
                        $("ul#question_list li:first").fadeIn("slow");
                    }
                });
    });
});

My Controller of Laravel 5 is-

public function add_question()
{
    return "OK";
    //return Request::input('question');
}

But getting something like this when requested-

enter image description here

What I am doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire