Tagged: laravel 5.6 ajax request example

Laravel ajax get Request Example From Scratch 0

Laravel ajax get Request Example From Scratch

Today, We want to share with you Laravel ajax get Request Example From Scratch.In this post we will show you Create Live Search In Laravel Using AJAX, hear for Laravel 5.7 Jquery Ajax Request Example From Scratch we will give you demo and example for implement.In this post, we will learn about AJAX call to a Laravel controller function / method with an example.

Laravel ajax get Request Example From Scratch

There are the Following The simple About Laravel ajax get Request Example From Scratch Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 5.7 Ajax GET and POST examples, so the Laravel 5.7 AJAX GET and show new data for this example is following below.

Step 1 : Define a Laravel Routes

Add Routes for Ajax Request:routes/web.php

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

Step 2: Create a Laravel Controller methods:

app/Http/Controllers/ProductController.php

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProductController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function productGetReq()
    {
        return view('productGetReq');
    }
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function productGetReqPost()
    {
        $input = request()->all();
        return response()->json(['success'=>'Get All the Product Simple jQuery Ajax Request.']);
    }
}

Step 3 : Create Laravel Blade File:

resources/views/productGetReq.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>pakainfo.com - Laravel 5.7 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>Create Live Search In Laravel Using AJAX - Pakainfo.com</h1>
        <form >
            <div class="form-group pakainfo">
                <label>Name:</label>
                <input type="text" name="name" class="form-control" placeholder="Name" required="">
            </div>
            <div class="form-group pakainfo">
                <label>company:</label>
                <input type="company" name="company" class="form-control" placeholder="company" required="">
            </div>
            <div class="form-group pakainfo">
                <strong>Qty:</strong>
                <input type="text" name="qty" class="form-control" placeholder="Qty" required="">
            </div>
            <div class="form-group pakainfo">
                <button class="btn btn-success save-product btn-submit">Submit</button>
            </div>
        </form>
    </div>
</body>
<script type="text/javascript">
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $(".save-product").click(function(e){
        e.preventDefault();
        var name = $("input[name=name]").val();
        var company = $("input[name=company]").val();
        var qty = $("input[name=qty]").val();
        $.ajax({
           type:'POST',
           url:'/productGetReq',
           data:{name:name, company:company, qty:qty},
           success:function(data){
              alert(data.success);
           }
        });
	});
</script>
</html>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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

I hope you get an idea about Laravel ajax get Request Example From Scratch.
I would like to have feedback on my Pakainfo.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.