2

I have a web service "someWebServiceOnServer" that sends back a json response and a Cookie. If I hit this URL through the browser, I see the following:

{"IsAuth":true,"Message":"","UserName":"guest"}

And if I inspect the page Resources -> Cookies, I see a Cookie set.

Now in my Sencha Touch 2 application, I am making an ajax call as follows:

Ext.Ajax.request({
url: 'someWebServiceOnServer',
useDefaultXhrHeader: false,
callback: function(options, success, response) {
console.log(response.responseText)
},
});

On running this, I get the JSON response as expected. But the cookie is not set. Also I cannot find the cookie in the response header. Why does this happen ?

Note: CORS has been implemented on the server and my application can access this service. I have not used withCredentials: true, since this throws an error XMLHttpRequest cannot load . Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true. .

Cookies are already enabled on my browser.

I need the cookie since I will be making subsequent calls that will send this cookie info back to the server.

Vijeth
  • 184
  • 8
  • Is your problem fixed? If Yes can you share your solution? – ThinkFloyd Mar 04 '13 at 10:44
  • Hi, I have the same problem, could you please suggest a solution? Many thanks! – GibboK Mar 04 '13 at 12:48
  • Check this out http://stackoverflow.com/questions/11616523/cookie-not-saved-in-sencha-touch-2-application?answertab=active#tab-top it is basically `withCredentials: true, useDefaultXhrHeader: false` – ThinkFloyd Apr 10 '13 at 09:39

2 Answers2

2

Try this:

Add the following headers to the server response.

Access-Control-Allow-Origin: http://clientdomain.com
Access-Control-Allow-Credentials: true

And add withCredentials: true in the Ajax request.

senchaDev
  • 587
  • 2
  • 6
  • 19
2

For IIS WCF with ExtJS request apply this to web.config (eg. for localhost so locally hosted application for example via SenchaTouch packagedr or PhoneGap):

<system.webServer>
          <httpProtocol>
            <customHeaders>
              <add name="Access-Control-Allow-Origin" value="http://localhost" />
              <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
              <add name="Access-Control-Allow-Credentials" value="true" />
            </customHeaders>
          </httpProtocol>
        </system.webServer> 

And In Ext.JS request use those parameters:

disableCaching: true,
useDefaultXhrHeader: false,
withCredentials: true

This in turn forces Ext.ajax.request to use cookies.

OSP
  • 1,458
  • 1
  • 14
  • 15