I have this code in javascript,
$(document).on('click', '.event-attendance-official', function() {
var id = $(this).parents('tr').data('event');
var data = {
id: id
}
submit(data, route('attendance.official'), function(data) {
console.log(data);
});
});
and the submit function
function submit(data, url, callback) {
$.ajax({
type: method,
url: url,
data: data,
dataType: 'json',
beforeSend: function(request) {
request.setRequestHeader("X-CSRF-TOKEN", $('meta[name="csrf-token"]').attr('content'));
},
complete: function(data) {
},
success: function(data) {
callback(data);
},
error: function(data) {
console.log('Error:');
}
});
}
which submit an id
to this code
public function getOfficialAttendance(Request $event)
{
return Attendance::with('user')
->where('event_id', '=', $event->id)
->where('did_attend', '=', 'true')
->get();
}
and the given route
Route::prefix('attendance')->group(function() {
Route::name('attendance.official')->post('/get/official/attendance','AttendanceController@getOfficialAttendance');
});
What this code does, is when I click on .event-attendance-official
a modal should prompt with the result from the request by the given ID using post.
the problem, is that, whenever, click on the same class I got this error in the console log.
Failed to load http://localhost/attendance/get/official/attendance: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://test.dev' is therefore not allowed access.
have you encountered the same problem? what did you do to resolved?