Symfony的,jQuery.ajax()调用,会话变量丢失 [英] Symfony, jQuery.ajax() call, session variables lost

查看:156
本文介绍了Symfony的,jQuery.ajax()调用,会话变量丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写使用的Symfony 1.3的web应用程序。我有一个问题,我的会话变量迷路我打电话,通过jQuery的一个动作后, $。阿贾克斯()通话。事情发生在顺序如下:

  1. 这是动作设置这样的会话变量:

      $这个 - >的getUser() - >的setAttribute(上传档案,$ UPLOADEDFILES);
     

  2. 然后,当操作调用视图组件,生成的HTML页面包含以下电话:

      $。阿贾克斯({
      键入:POST,
      网址:'< PHP的回声url_for(内容/合并); ?>',
      缓存:假的,
      成功:mergingCompleteCallback
    });
     

  3. 我点击触发上述Ajax调用按钮。呼叫执行相应的操作方法,但是当我打印出来的上传档案会话变量的内容,它是空的。

    我也检查,看看是否会话ID停留在调用该设置变量的页面,并且读取变量(Ajax调用)和会话ID没有改变的页面之间的相同。我在几个小时在网上搜索,我无法找到一个解决方案。

解决方案

我有类似的问题,这个问题是,我使用的主机值存储饼干WWW,即www.mydomain.com,我是做没有Ajax请求的 WWW

解决方案是使用像主机通配符。 例如 .mydomain.com 作为主机来存储会话cookie的浏览器端。

只要确定你是不是这样的受害者?

I am writing a web app using Symfony 1.3. I have a problem with my session variables getting lost after I call an action via jQuery's $.ajax() call. Things happen in this order:

  1. An action sets the session variable like this:

    $this->getUser()->setAttribute('uploaded-files', $uploadedFiles);
    

  2. Then when the action calls the view component, the resulting HTML page contains the following call:

    $.ajax({
      type: "POST",
      url: '<?php echo url_for("content/merge"); ?>',
      cache: false,
      success: mergingCompleteCallback
    });
    

  3. I click on the button that triggers the above ajax call. The call executes the corresponding action method, but when I print out the content of the 'uploaded-files' session variable, it's empty.

    I also checked to see if the session id stays the same between the call to the page that sets the variable and the page that reads the variable (the ajax call) and the session id hasn't changed. I was searching for hours online and I wasn't able to find a solution.

解决方案

I had the similar problem, and the issue was that I was using host value for storing cookies with 'www' i.e. www.mydomain.com and I was making Ajax request without 'www'

The solution is use the wildcard like host. Like .mydomain.com as your host to store session cookie on browser end.

Just make sure you are not a victim of this?

这篇关于Symfony的,jQuery.ajax()调用,会话变量丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆