Laravel 9 Ajax Get Request Example Tutorial

Hello Artisan,

In this example, I will discuss how to create an ajax get request to get data from the server and show it in the browser without page refresh. If you don't know how to make a get request in ajax in laravel application then this example is for you.

I will show you step by step guide on how to show data on modal in laravel using ajax get request. I will show you step by step so that you can understand. In this example, we will create a list of users with an edit button. When you click on the show button then we will open the modal and get data using ajax to display. you can fetch data using jquery ajax get in laravel 6, laravel 7, laravel 8 and laravel 9 version as well.

Let's see the example of how to use ajax get request in Laravel application:


Step 1: Install Laravel 9

In this step, we will install a fresh Laravel application. Run the below command to install:

composer create-project --prefer-dist laravel/laravel:^9.0 laravel


Step 2 : Create Route

In this step, we need to create a route for creating show data with the bootstrap modal. So create it.


Route::get('/', 'TestController@index')->name('root');
Route::get('/color/{id}/edit', 'TestController@update')->name('color.update');


Step 3 : Create Controller 

In this step, we have to create a test controller. So create it and then paste this below code to create show data with modal in laravel.


namespace App\Http\Controllers;

use App\Category;
use Illuminate\Http\Request;

class TestController extends Controller
    public function index()
    	$category = Category::all();
    	return view('home',compact('lija'));

    public function update($id)
    	$category = Category::find($id);

	    return response()->json([
	      'data' => $category


Step 4 : Create View

Now in this final step, we have to create our home.blade.php. so create it and paste this below code with modal.



Read also: How To Install Vite in Laravel 9 with React Js


Hope it can help you.


#laravel #laravel-9x #ajax