Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

Laravel 6 JQuery Ajax Post Request Example

Today, We want to share with you Laravel 6 JQuery Ajax Post Request Example.In this post we will show you Ajax Post Request Example in Laravel 6, hear for laravel url route with parameters we will give you demo and example for implement.In this post, we will learn about Laravel 6 AJAX GET and POST Request Complete Tutorial with an example.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

Laravel 6 JQuery Ajax Post Request Example

There are the Following The simple About Laravel6 JQuery Ajax Post Request Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel6 Ajax Form Submit With Validation Tutorial, so the some major files and Directory structures for this example is following below.

Phase 1: Define Laravel 6 Routes

routes/web.php

Route::get('getProductList', '[email protected]');

Route::post('getProductList', '[email protected]')->name('getProductList.post');

Phase 2: Create Laravel 6 Controller

app/Http/Controllers/HomeController.php

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class ProductController extends Controller
{

    /**
     * Create a new controller instance.
     *
     * @return void
     */

    public function getProductList()
    {
        return view('ajaxRequest');
    }

    /**
     * Create a new controller instance.
     *
     * @return void
     */

    public function ajaxRequestPost(Request $request)
    {
        $input = $request->all();
        \Log::info($input);
        return response()->json(['success'=>'Got Simple Ajax Request.']);
    }
}

Phase 3: Create Laravel 6 Blade File

resources/views/getProductList.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Laravel 6 Ajax Request example</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <meta name="csrf-token" content="{{ csrf_token() }}" />
</head>
<body>

    <div class="container">
        <h1>Laravel 6 Ajax Request example - View Products</h1>
        <form >
            <div class="form-group">
                <label>Product Name:</label>
                <input type="text" name="name" class="form-control" placeholder="Product Name" required="">
            </div>
            <div class="form-group">
                <label>Product Price:</label>
                <input type="text" name="price" class="price form-control" placeholder="Product price" required="">
            </div>
            <div class="form-group">
                <strong>Description:</strong>
                <input type="text" name="slug" class="form-control" placeholder="description" required="">
            </div>
            <div class="form-group">
                <button class="btn btn-success btn-submit">Submit</button>
            </div>
        </form>
    </div>
</body>
<script type="text/javascript">

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

    $(".btn-submit").click(function(e){
        e.preventDefault();
        var name = $("input[name=name]").val();
        var price = $("input[name=price]").val();
        var slug = $("input[name=slug]").val();

        $.ajax({
           type:'POST',
           url:"{{ route('getProductList.post') }}",
           data:{name:name, price:price, slug:slug},
           success:function(data){
              alert(data.success);
           }
        });
	});
</script>
</html>

results

[2019-09-17 03:54:19] local.INFO: array (
  'name' => 'Mobile Apple',
  'price' => '2578.56',
  'slug' => 'mobile-apple',
)  

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about jQuery Ajax POST with PHP-Laravel6.
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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel 6 return view jQuery ajax request example
  2.   jQuery Ajax POST example with Laravel 7/6
  3.   laravel ajax csrf tokens Example jQuery Ajax Call
  4.   Angular 6 Image Upload with Validation Example
  5.   Simple JQuery Ajax Request Example with Laravel 6
  6.   PHP AJAX Live Search Box Autocomplete Using MySQL Database
  7.   Laravel Return Ajax JSON Response Example
  8.   Simple Angular 6 Routing and Single Page View Tutorial
  9.   Laravel 6 JQuery Ajax Post Request Example
  10.   laravel Check Request is Ajax Example