使用Ajax请求在煎茶触摸2.0获取饼干 [英] Getting Cookies in Sencha touch 2.0 using Ajax request

查看:92
本文介绍了使用Ajax请求在煎茶触摸2.0获取饼干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用煎茶触摸2.0的Web移动项目

I'm developing a web mobile project using Sencha touch 2.0

我做了一个Ajax请求如下:

I made an ajax request as follows:

Ext.Ajax.request({
  url: myUrl,
  params: {
    format: 'xml',
    callback: 'success'
  },
  method :'POST',
  xmlData :MyXMLData
  proxy:{
    type: 'ajax',
    reader:{
      type: 'xml',
      rootProperty:'ns2:user'
    }
  },

在服务器端我有以下标题设置:

On the server-side I have the following headers set:

header("Access-Control-Allow-Origin: *");

服务器返回一个XML响应和饼干

The server returns an XML response and cookies

通过使用Chrome的调试工具,我可以看到各种设置Cookie头返回

By using Chrome's debugging tools I can see that various Set-Cookie headers are returned

现在的问题是我怎么可以为了得到这些cookies来与其他请求??

The question is how can I get these Cookies in order to be set with other requests??

请注意:

我试过response.getAllResponseHeaders(),但是这并不能与集-Cookie的工作。

I tried response.getAllResponseHeaders() but this doesn't work with Set-Cookies.

推荐答案

在这里找到了答案: http://stackoverflow.com/ A /一百十万六千八百七十七分之七百十八万九千五百零二

就如何做到这一点几乎没有指导不幸的是煎茶论坛的答案。 在煎茶触摸,相当于解决了什么样的链接上面说的是:

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是真实的,useDefaultXhreader是假的。这允许您的Ajax请求查找,设置,并要求以饼干为可用。当然,这一切都假定你的服务器是建立跨域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.

这篇关于使用Ajax请求在煎茶触摸2.0获取饼干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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