I'm trying to update field $medic->current according to my logic. I'm new to ajax and i just need to get it started.
In my code i calculate the difference between two dates { $medic->end_day , current date }. Based on their difference in dates i change the "current" field. If difference < 0 , current = 0 else current = 1 is what I'm trying to do.
So how to use AJAX to edit the "current" field of $medic. Below is the code.
<script>
window.onload = checkcurrent;
var today = new Date();
@foreach($medics as $medic)
@if($medic->current == 1)
function checkcurrent()
{
var status = ;
var last_date= new Date('');
var new_last_date = new Date(last_date.getFullYear(),last_date.getMonth(),last_date.getDate());
var diff = parseInt((new_last_date - today) / (1000 * 60 * 60 * 24));
if(diff<0)
{
status = 0;
$.ajax({
url: "",
type: "POST",
data: { current: 0 } ,
success: function (response) {
console.log('success');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
}
else
{
status = 1;
}
}
@endif
@endforeach
</script>
I just want help with the ajax code because rest is fine and working. When status is 0, I want to edit the "current" field to 0. How to do this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire