My.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="csrf-token" content="{{ csrf_token() }}">
</head>
<body>
<script src="https://code.jquery.com/jquery-3.6.1.min.js"
integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script>
$(document).ready(function() {
var my = "{{ route('my_route') }}";
//click to nofication bell icon
$(".notficationBell").click(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: my,
type: 'POST',
success: function(data) {
alert(data);
}
});
});
});
</script>
</body>
</html>
web.php<?php
use App\Http\Controllers\admin\MyController;
Route::post('test', [MyController::class, 'testAjax'])
->name('my_route');
MyController.php
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class MyController extends Controller
{
public function testAjax(Request $request)
{
return "working";
}
}
Comments
Post a Comment
If you any doubt of any topic then you can comment me.