2014-11-24 66 views
0

我有这样的从http://fromDomain.com这样的HTML和张贴到http://toDomain.com这是一个轨道应用程序。跨域后刷新清除会话值

<html> 
    <h1>Test Redirect with Post</h1> 
    <button id="submit" onclick="send_form()">Submit</button> 

    <script> 
    function send_form() { 
     var form = document.createElement("form"); 
     form.setAttribute("method", 'post'); 
     form.setAttribute("action", 'http://todomain.com/someaction'); 
     form.appendChild(addElement('field1', 'field1')); 
     form.appendChild(addElement('field2', 'field2)'); 
     document.body.appendChild(form); 
     form.submit();} 

    function addElement(key, value){ 
     var hiddenField = document.createElement("input"); 
     hiddenField.setAttribute("type", "hidden"); 
     hiddenField.setAttribute("name", key); 
     hiddenField.setAttribute("value", value); 
     return hiddenField;} 
    </script> 
    </html> 

在rails应用程序中,我正在做类似这样的事情。

def someaction 

if not session[:token] 
session[:token] = @self.getsomehash 
end 
end 

问题是后http://todomain.com/someaction页面加载如果用户点击浏览器刷新那么它将重新发布的页面和会话哈希被重置。看起来像我当浏览器做转发轨道创建一个新的会话,而不是使用现有的。

我的假设是正确的吗?有什么方法可以刷新并仍然坚持这些值吗?

+0

我对RoR托管环境并不是很熟悉,但会话cookie(临时cookie)通常存储在用户代理中以在这些情况下识别访问者。无论RoR如何进行其状态管理,服务器端都应该采用这种机制。你使用哪种浏览器? – 2014-11-24 15:02:10

+0

您是否可以使用浏览器的开发者模式来确定您的浏览器在首次访问该网页/网站后是否为存储会话Cookie?..它应该有与会话cookie关联的域(Scope)值,如果正在创建第一个会话Cookie,是否将指定为域? – 2014-11-24 15:05:29

+0

我使用的是Chrome浏览器,如果您推荐的浏览器,我可以使用任何浏览器进行测试。我也会检查域的范围。 – NMK 2014-11-24 15:18:21

回答

0

听起来像你需要Redirect-on-POST模式 - 基本上你需要配置你的服务器应用程序发送重定向响应每个POST请求。

+0

谢谢,让我读更多关于这个话题。 – NMK 2014-11-24 15:18:48