Getting Cookies in Sencha touch 2.0 using Ajax req

2019-09-02 07:42发布

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

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: *");

The server returns an XML response and cookies

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

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

Note:

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

2条回答
来,给爷笑一个
2楼-- · 2019-09-02 08:09

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.

查看更多
做个烂人
3楼-- · 2019-09-02 08:21

As far as I know , you can send the cookie to the server which is in a different domain by making a cross domain AJAX call.Just include

    withCredentials : true,
    useDefaultXhrHeader : false,

The set-Cookie value can be seen in request and response headers , but it cannot be accessed through javascript if the client and server are on different servers.

查看更多
登录 后发表回答