Answer the question
In order to leave comments, you need to log in
Why doesn't the view display?
Hello everyone, I don’t know how to do it anymore), in general I do ajax like this
$this->registerJs("
$('.send').on('click', function() {
if($(\"textarea[name='textarea']\").val()){
$.ajax({
type: 'POST',
url: 'time-checker/complete-comment/',
data: {
val: $(\"textarea[name='textarea']\").val()
}
});
} else {
$(\"textarea[name='textarea']\").css({'border-color':'#d8512d'});
setTimeout(function(){
$(\"textarea[name='textarea']\").css({'border-color':'rgba(222, 222, 222, 1)'});
},1000);
}
$('.btn-outline, .close').on('click', function() {
location.reload();
});
});
");
public function actionCompleteComment()
{
if (Yii::$app->request->isAjax) {
$data["time"] = UserTimeReport::find()->where(['user_id'=>Yii::$app->user->id, 'date'=>Yii::$app->params['dateToday']])->asArray()->one();
$fst = time() - $data["time"]["start"];
$new_time_work = $fst - $data["time"]["pause"];
$model = UserTimeReport::findOne([
'user_id'=>Yii::$app->user->id,
'date'=>Yii::$app->params['dateToday']
]);
$model->end = time();
$model->work = $new_time_work;
$model->comment = $_POST['val'];
$model->update();
$data["st"] = date("H:i:s", $data["time"]["start"]);
$data["ed"] = date("H:i:s", $model->end);
return $this->renderAjax('modal', ['data' => $data]);
} else {
throw new ForbiddenHttpException('что-то не так');
}
}
return $this->renderAjax('modal', ['data' => $data]);
<div class="modal modal-success" id="modal-success" style="display: none; padding-right: 17px;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title">Вы завершили рабочий день!</h4>
</div>
<div class="modal-body">
<table class="table">
<thead>
<tr>
<th>Старт</th>
<th>Пауза</th>
<th>Завершил</th>
<th>Работа</th>
<th width="50">
</th>
</tr>
</thead>
<tbody>
<tr>
<td><?= $data["st"]?></td>
<td><?= $data["ps"]?></td>
<td><?= $data["ed"]?></td>
<td><?= $data["wk"]?></td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<?php
$this->registerJs("
$('#modal-success').modal('show');
$('.btn-outline, .close').on('click', function() {
location.reload();
});
");
?>
Answer the question
In order to leave comments, you need to log in
You are making an ajax request and not processing the response from the server in any way. The server returns you the html that you rendered, but you need to write code in js in the ajax request handler that will show it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question