Monday, April 16, 2018

CSRF token error? on laravel Symfony\Component\HttpKernel\Exception\HttpException - development

CSRF token error? on laravel SymfonyComponentHttpKernelExceptionHttpException

first was ok. second got error
enter image description here
I use the ajax function on javascript page in laravel

If I initiate the function once it work well
But when I start the function 2 or 3 times in short time I got the error

"exception": "SymfonyComponentHttpKernelExceptionHttpException",
"file": "D:AppServwwwcomevendorlaravelframeworksrcIlluminateFoundationExceptionsHandler.php",

I search the error message . The result is the csfr issue.

But how can I fix the error?
I have already have the

$.ajax({
                headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },

The question is not on the first time . It’s on the second or third times.

Code

$('.findNews_geography').autocomplete({   
        source: function(request, response) {
            var findtable=$('.findtable_num').val();
            var terms=request.term; 
            console.log("findtable="+findtable+";term="+terms);
            $.ajax({
                headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },


                url: "findNews_geography",
                dataType: "json",
                type: "post",
                data: {
                    findtable : findtable,
                    term : terms,
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    console.log("findNews_geography ajax error="+xhr.responseText);
                    console.log("findNews_geography xhr.status="+xhr.status+";thrownError="+thrownError);
                },
                success: function(data) {
                    console.log("see request="+data);
                    response( $.map( data, function( item ) {
                        return {
                            label: item.place,
                        }

                    }));
                } //success end
            }); //ajax end
        }, //source end
        minLength: 0, 
}); //autocomplete end




 $(".findNews_geography").focus(function () {
         //if (this.value == "") {
       console.log("findNews_geography get focus");
        if($('.findtable_num').val()){
            $(this).autocomplete("search"); 
        }// }; 
  });



from Laravel Questions and Answers https://laravelquestions.com/laravel/csrf-token-error-on-laravel-symfonycomponenthttpkernelexceptionhttpexception/
via Lzo Media

No comments:

Post a Comment