Cookie未保存在sencha touch 2应用程序中 [英] Cookie not saved in sencha touch 2 application

查看:105
本文介绍了Cookie未保存在sencha touch 2应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的响应标头中接收到具有有效set-cookie值的服务器响应时,应用程序不会保存Cookie。

Upon receiving a server response with valid "set-cookie" value in my response header, application does not save the cookie.

在heroku上的Rails服务器是为CORS(跨域ajax请求)设置的。

Rails server on heroku is setup for CORS (cross domain ajax requests). Access-Control-Allow-Credentials = True and methods = POST, GET.

响应包含set-cookie的登录请求如下:

Login request, for which the response contains set-cookie, is as follows:

 Ext.Ajax.request({
            url: 'http://myurl/log_user_in.json',
            params: { username: user, password: pass, app_id: id },
            method: "POST" });

需要帮助为什么应用程序不保存cookie。即。执行
document.cookie ,获得set-cookie后会产生 document.cookie =''

Need help on why the application does not save the cookie. ie. executing document.cookie , after getting "set-cookie" results in document.cookie = ''

感谢您的帮助。

推荐答案

http://stackoverflow.com/a/7189502/1106877

不幸的是,Sencha论坛的答案几乎没有提供如何做到这一点的指导。
在Sencha Touch中,与上面链接相同的解决方案是:

Unfortunately Sencha Forum answers provided almost no guidance on how to do this. In Sencha Touch, the equivalent solution to what the link above says is:

Ext.Ajax.request({
            url: 'http://myurl/log_user_in.json',
            params: { username: user, password: pass, app_id: id },
            withCredentials: true,
            useDefaultXhrHeader: false,
            method: "POST" });

它也适用于使用Ajax的商店代理。

It also works well with your store proxy using Ajax.

确保withCredentials为true,useDefaultXhreader为false。这允许您的ajax请求查找,设置和请求与可用的cookie。当然,假设您的服务器设置为跨域Ajax调用。

Ensure withCredentials is true and useDefaultXhreader is false. This permits your ajax request to look for, set, and request with cookies as available. Of course all this assumes your server is setup for Cross Domain Ajax calls.

这篇关于Cookie未保存在sencha touch 2应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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