I've developed a JavaScript script and Controller Action to update a field when a button is clicked as shown below.
Although I receive a success response, the table does not get updated.
public function actionSetstarttime()
{
if (Yii::$app->request->isAjax) {
$data = Yii::$app->request->post();
$mySaveId = $data['save_id'];
$timeRecord = teammembers::find()
->where(['=', 'id', $mySaveId])
->one();
$timeRecord->time_start = 12345;
//Yii::$app->formatter->asDatetime('now', 'php:Y-m-d H:i:s');
$timeRecord->save(false);
return $timeRecord->time_start;
}
} // }}}
The JavaScript code in the view is:
$('._starttime').on('click', function(event){
event.preventDefault();
$.fn.timer.worker.go();
var first = $("#timeslot_id").val();
$.ajax({
type: "POST",
url: "/site/time",
data: 'save_id='+first,
success: function (data) {
//do something
console.log(data);
alert("working");
},
error: function (exception) {
console.log(exception);
}
});
});