php - Get Data from .json file with AJAX/JQUERY in Laravel
one text
I wanna get data from .json
file when i click the button with AJAX/JQUERY in Laravel but I cannot solve that.
When click the .more
button, only it showing alert in error:
. I cannot get any error from Laravel side.
Here is the details ;
My JS file :
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(".modal").on('click', function () {
$.ajax({
route: '/getjsonfile',
type: 'GET',
dataType: 'JSON',
success: function () {
alert("OKAY!");
},
error: function () {
alert("JSON FILE NOT FOUND!");
}
});
});
Here is my route :
Route::get('/getjsonfile', [App\Http\Controllers\Admin\AjaxController::class, 'getjsonfile'])->name('getjsonfile');
Here is my function in AjaxController
:
public function getjsonfile()
{
$request = new Request();
$json_file = File::get("data/table-datatable.json");
return $json_file;
}
Here is my .more
button:
<button type="button" class="more" data-bs-toggle="modal">More</a>
Source