Jquery symfony2会话需要2次刷新才能更新
我创建了一个在每个页面上运行的控制器,它除了一个方面外都正常工作 在我的Jquery symfony2会话需要2次刷新才能更新,jquery,session,symfony,Jquery,Session,Symfony,我创建了一个在每个页面上运行的控制器,它除了一个方面外都正常工作 在我的base.html.twig文件中,我放置了:{%render“EcsCrmBundle:Module:checkClock”%} 因此,我有一个名为ModuleController的控制器,其动作为checkClockAction,其中包含以下代码: <?php namespace Ecs\CrmBundle\Controller; use Symfony\Bundle\FrameworkBundle\Contr
base.html.twig
文件中,我放置了:{%render“EcsCrmBundle:Module:checkClock”%}
因此,我有一个名为ModuleController
的控制器,其动作为checkClockAction
,其中包含以下代码:
<?php
namespace Ecs\CrmBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Ecs\CrmBundle\Entity\TimeClock;
class ModuleController extends Controller
{
public function checkClockAction() {
$em = $this->getDoctrine()->getEntityManager();
$user = $this->get('security.context')->getToken()->getUser();
$today = time();
$start = date('Y-m-d 00:00:00');
$entities = $em->getRepository('EcsCrmBundle:TimeClock');
$query = $entities->createQueryBuilder('tc')
->select('tc.in1, tc.out1, tc.in2, tc.out2, tc.in3, tc.out3')
->where('tc.noteBy = :user')
->andWhere('tc.daydate >= :start')
->setParameter('user', $user->getid())
->setParameter('start', $start)
->setMaxResults('1')
->getQuery();
$entities = $query->getOneOrNullResult();
if (empty($entities)) {
$ents = "clocked_out";
$this->get('session')->set('clockedin', 'clocked_out');
} else {
for ($i=1; $i <= 3; $i++) {
if ($entities["in$i"] != NULL) {
$ents = "clocked_in";
$this->get('session')->set('clockedin', 'clocked_in');
if ($i == 1) {
$this->get('session')->set('nextclock', "out$i");
} else {
$x = $i+1;
$this->get('session')->set('nextclock', "out$x");
}
if ($entities["out$i"] != NULL) {
$ents = "clocked_out";
$this->get('session')->set('clockedin', 'clocked_out');
$x = $i+1;
$this->get('session')->set('nextclock', "in$x");
}
if ($entities["out3"] != NULL) {
$ents = "day_done";
$this->get('session')->set('clockedin', 'day_done');
}
}
}
}
return $this->render('EcsCrmBundle:Module:topclock.html.twig', array(
'cstat' => $ents,
));
}
}
问题是,即使页面刷新,会话也不会更新,直到我再次手动刷新页面。。。关于我做错了什么有什么想法吗?您正在使用
location.reload(true)代码>应该忽略浏览器缓存的内容
可能发生的情况是,当您访问该页面时,您的一个操作触发以更改会话的状态
例如:访问页面(将操作设置为X)。
AJAX请求:将操作设置为Y。
刷新:将操作设置为X。
再次刷新:将操作设置为Y
对于一些调试帮助,您是否可以让AJAX请求返回会话的当前状态,以便在会话更改时可以看到它?问题是,当您打卡时,会话没有被设置。。它在页面重新加载时设置。。。所以每次发送会话的当前状态都会返回#。。。其中#是1、2或3
$(".clocker").click(function() {
// lets send the ajax request to clockin..
$.ajax({
url: $(this).attr('href'),
type: "POST",
data: "url="+document.URL,
success: function(response) {
location.reload(true);
return false;
}
});
return false;
})