Ajax not working in laravel 5.6

Today, We want to share with you Ajax not working in laravel 5.6.In this post we will show you laravel api post request not working, hear for ajax url in laravel we will give you demo and example for implement.In this post, we will learn about laravel ajax response with an example.

Ajax not working in laravel 5.6

There are the Following The simple About request::ajax in laravel Full Information With Example and source code.

As I will cover this Post with live Working example to develop ajax is not a function laravel, so the laravel ajax get not working is used for this example is following below.

Laravel is a web application framework with expressive, elegant syntax.The PHP Framework for Web Artisans,freeing you to create without sweating the small things. CRUD Operation With Server Side.

Keywords : $request- ajax() laravel not working,laravel ajax get not working,ajax post not working,ajax is not a function laravel,laravel api post request not working,ajax url in laravel,laravel ajax response,request::ajax in laravel,ajax request example laravel 5.7, laravel 5.7 ajax request example, jquery ajax in laravel 5.7, ajax post request laravel 5.7, laravel 5.7 ajax post data to controller, passing data from ajax to controller laravel 5.7, laravel 5.7 get ajax data

AJAX POST Request not working in Laravel 5.6



var pass= {'_token':$('meta[name="token"]').attr('content'),
            'MessageContent': document.getElementById("sendproducts").value,

//Ajax call

        data: pass,
    }).fail(function(jqXHR, textStatus, error){

JQuery Ajax Post Request Example in Laravel

Create Routes for Ajax:routes/web.php

Route::get('ajaxRequest', 'MemberController@ajaxRequest');

Route::post('ajaxRequest', 'MemberController@jqAjaxRehttp');

Create Controller in Laravel:


namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MemberController extends Controller
     * Create a new controller instance.
     * @return void
    public function ajaxRequest()
        return view('ajaxRequest');
     * Create a new controller instance.
     * @return void
    public function jqAjaxRehttp(Request $request)
        $input = $request->all();
        return response()->json(['success'=>'Got Simple Ajax Request.']);

Create Blade File:


    Laravel 5.6 Ajax Request example - www.pakainfo.com


Laravel 5.7 Ajax Request example

Member Email:

Ajax Post not Working in laravel
If you’re having issues with an Ajax post not working in Laravel, there are a few things you can check:

Verify that the route is correct: Make sure that the route you’re posting to exists and is correct. You can check this by running php artisan route:list in your terminal and checking if the route is listed.

Check the CSRF token: Laravel includes CSRF protection by default, which requires you to include a CSRF token in your post request. Make sure that you’re including the CSRF token in your Ajax post. You can do this by adding the following line of code to your HTML head section:

Then, in your Ajax post, include the CSRF token in the request headers like this:

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

Verify that the request is being sent: Use the browser developer tools to check that the Ajax post request is actually being sent to the server. Check the network tab in your browser’s developer tools and look for the Ajax post request. If it’s not there, then there might be an issue with your JavaScript code.

Check the response from the server: If the Ajax post request is being sent but not getting the desired response, check the response from the server. You can do this by using the success and error callbacks in your Ajax post.

For example, you can add the following code to your Ajax post to log the response from the server to the console:

    type: 'POST',
    url: '/your/route',
    data: {your: 'data'},
    success: function(response) {
    error: function(jqXHR, textStatus, errorThrown) {
        console.log(textStatus, errorThrown);

By following these steps, you should be able to identify the issue and fix your Ajax post request in Laravel.

Web Programming Tutorials Example with Demo

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about ajax post not working.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment