Reputation: 1594
As I already mentioned in title sometime the ajax request respond internal server error. I am working on an application i which a send a lot of ajax requests, some requests are sent after regular interval of time by using setInterval and setTimeout functions. On the other hand, some requests depend upon the user actions.
I am very confused sometime the ajax request give server error but why? If it was a syntax error it should give this error every time. Here is one of the code of the ajax request from my requests
@if(Auth::check())
updateLastActivity();
@endif
function updateLastActivity(){
$.ajax({
headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
url:'{{route('user.updateLastActivity')}}',
type:'get',
success:function(data,status){},
complete:function(data){
setTimeout(updateLastActivity,5000);
}
});
}
here is the server code behind this request.
public function updateLastActivity(){
$activity=Useractivity::find(session()->get('last_activity_id'));
$activity->updated_at=date('Y-m-d H:i:s');
$activity->save();
return response('success');
}
How to resolve that issue.
Upvotes: 0
Views: 49