How to call Laravel Route in Jquery and Javascript

This tutorial about how to call laravel routes in jquery and ajax.

Call Laravel routes in jquery

If you see how to call laravel routes in javascript and jquery then yes there are several ways.

Let we have two examples first is simple route where no any variable pass with route and other is a variable pass with route.

<?php
Route::get('user-list',[UserController::class,'index'])->name('user.list');
Route::get('user-edit/{id}',[UserController::class,'edit'])->name('user.edit');
Exampl 1 Simple route
<script>
	var url = "{{ route('user.list') }}";
</script>
Exampl 2 pass a variable in route
<script>
	var url = "{{ route('user.edit', $id) }}";
	location.href = url;

	//or
	var id = '12';
	var url = "{{ route('user.edit', ':id') }}";
	url = url.replace(':id', id);
	location.href = url;

</script>
php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links