Cookie not saved in sencha touch 2 application

霸气de小男生 提交于 2019-12-06 12:41:26

问题


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

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

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" });

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

Thanks for your help.


回答1:


Found the answer here: https://stackoverflow.com/a/7189502/1106877

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" });

It also works well with your store proxy using 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.



来源:https://stackoverflow.com/questions/11616523/cookie-not-saved-in-sencha-touch-2-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!