Answer the question
In order to leave comments, you need to log in
Yii: Pjax + JQuery.click() + setIntreval. Why is only the last click executed?
Hello.
The view in the foreach loop displays 1 or more PJax.
Inside pjax is a link with a class that is unique to that link.
Sessions are in progress. We are trying to update the time counter.
pjax code:
<?php Pjax::begin([
'enablePushState' => false,
]); ?>
<?php
$old_date = new DateTime($order['creation_time']);
$old_date->add(new DateInterval('P0Y0M0DT0H30M0S'));
$now_date = new DateTime($actualtime);
$interval = $old_date->diff($now_date, false);
echo "<a href='/cart/gettime?id={$order['game_id']}' class='gettime'>".$interval->format("%I : %S")."</a>";
?>
<?php Pjax::end(); ?>
public function actionGettime() {
$id = Yii::$app->request->get('id');
if(!empty($id)) {
$session = Yii::$app->session;
$session->open();
$order = $session['cart'][$id];
$actualtime = Yii::$app->formatter->asDate('now', 'php:Y-m-d H:i:s');
return $this->renderAjax('gettime', compact('order', 'actualtime'));
} else {
return '0';
}
}
$(document).ready(function() {
setInterval(function(){
$('.gettime').each(function() {
$(this).click();
});
}, 1000);
});
var g = $(this).attr('id');
console.log(g);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question