我希望在用户点击内容时看到已发送的消息,但我会继续收到此消息。
从看到的消息的空值创建默认对象
代码:
<div class="chat-body">
<div class="chat-content override align-left color-text2 seen">
<input type="hidden" class="id" value="id" />
<p class="font-size-18"><?php echo ucfirst($msg['subject']);?></p>
<p><?php echo strip_tags($msg['content']);?></p>
<time class="chat-time" datetime="2015-06-01T08:30">
<?php echo date("D, d M, Y | H:i:s", strtotime($msg['created_at'])); ?>
</time>
</div>
</div>
jquery的:
$(document).on('click','.seen',function() {
$.ajax({
type:"POST",
url:baseUrl+"/message/seen",
data:{id:$('.id').val()},
success: function(response) {
var res = $.parseJSON(response);
}
});
});
控制器:
public function actionSeen(){
if(Yii::$app->request->isAjax){
$message = MessageTo::find()->where(["id" => $_POST['id']])->one();
$message->is_seen = 1;
$message->update();
echo json_encode(TRUE);die;
} else {
echo json_encode(FALSE);die;
}
}