Error Ajax LARAVEL 419 POST error

+1 vote

My ajax call is something like

$(document).ready(function() {
    $("#company").click(function() {
        $.ajax({
            type: "POST",
            dataType:'html',
            url : "/company",
            success : function (data) {
                $("#result").html(data);
            }
        });
    });
});

I am calling the view through my route

Route::post('/company', 'Ajaxcontroller@loadContent');

And controller

public function loadContent()
    {
        return view('listing.company')->render();
    }

My com.blade.php is

    @foreach ($companies as $company)
            <div class="posting-description">
            <h5 class="header"><a href="#"></a>{{$company->name}}
            </h5>
            <h5 class="header"> {{$company->streetaddress}} {{$company->postalcode}}</h5>  
            <p class="header">
             <span class="red-text"> <?= $service; ?> </span> is available on <span class="green-text"><?php echo $date; ?></span>
           </p>
    @endforeach

I am getting this error

POST http://127.0.0.1:8234/dey 419 (unknown status)

How to resolve this error?

Jun 16, 2020 in PHP by kartik
• 37,520 points
3,755 views

1 answer to this question.

+1 vote

Hello @kartik,

Laravel 419 post error is usually related with api.php and token authorization

Laravel automatically generates a CSRF "token" for each active user session managed by the application. This token is used to verify that the authenticated user is the one actually making the requests to the application.

Add this to your ajax call

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

or you can exclude some URIs in VerifyCSRF token middleware

 protected $except = [
        '/route_you_want_to_ignore',
        '/route_group/*
    ];

Hope it helps!!

answered Jun 16, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

Error:Sending Form file with form using AJAX

Hello @kartik, Don't pass the files into the ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,840 points
4,034 views
0 votes
1 answer

How to post the parameter in ajax call of jquery datatable?

Hello @kartik, Just pass it like a normal ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,840 points
18,137 views
0 votes
1 answer

Error:PHP Warning: POST Content-Length of 8978294 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

Hello @kartik, 8388608 bytes is 8M, the default ...READ MORE

answered Sep 17, 2020 in PHP by Niroj
• 82,840 points
28,542 views
0 votes
1 answer

How to route GET and POST for same pattern in Laravel?

Hello @kartik, You could try the following: Route::controller('login','AuthController'); Then in ...READ MORE

answered Nov 22, 2020 in PHP by Niroj
• 82,840 points
3,103 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,012 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,995 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,918 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,696 views
0 votes
1 answer

Error:Jquery .ajax method=“post” but $_POST empty

Hello @kartik, Instead of method: "post" you need to use type: ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,840 points
3,658 views
0 votes
1 answer

Error:uncaught exception: out of memory in Ajax Process

Hello @kartik, From your description of being redirected ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,840 points
1,897 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP