I would really appreciate some help on this. I tried tons of solutions as posted in this forum, but I cannot get it to work.
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 company.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/company 419 (unknown status)
This is a very common issue when you got the 419 page expired issue in the Laravel application. This happens due to inactivity on the page for a long time. Laravel handles the form request with a CSRF (Cross-Site Request Forgery) token. For every form submit, Laravel generates a new token.
What does 419 HTTP Status Code Mean? The HTTP Status Code 419 indicates that a session has expired while processing a post request.
The Session Expired or 419 Page Expired error message in Laravel comes up because somewhere your csrf token verification fails which means the App\Http\Middleware\VerifyCsrfToken::class middleware is already turned on. In the form the @csrf blade directive is already added, which should be fine as well.
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/* ];
419 error happens when you don`t post csrf_token. in your post method you must add this token along other variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With