0

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.

Developer
  • 1,713
  • 2
  • 14
  • 26

2 Answers2

3

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.

Community
  • 1
  • 1
Austin
  • 2,936
  • 2
  • 14
  • 16
0

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.

Termi
  • 611
  • 7
  • 12