1

I'm developing an Extjs-6 application. My server application is RestFul. I have to login with Ajax. I send an Ajax request as follow:

Ext.Ajax.request({

   url: 'localhost:8084/Calk/j_spring_security_check',
   params: {j_username: 'ali', j_password: '123456',
   method: 'POST',
   headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
   },
   success: ...,
   faiulure: ...,
});   

Result of the request is as follow: enter image description here

After client receive 200 OK, it read a store as follow:

Ext.define('Calk.store.Calk', {
   extend: '...',
   model: '...',
   proxy: {
      type: 'ajax',
      url: 'localhost:8084/Calk/calk/all',
      withCredentials: true,
      useDefaultXhrHeader: false,
      reader: ...,
      method: 'POST'
});    

But result is as follow: enter image description here

Why cookie set wrong? How Can I Fix it?

sideshowbarker
  • 72,859
  • 23
  • 167
  • 174
Morteza Malvandi
  • 1,426
  • 5
  • 28
  • 67
  • The cookie is restricted to `localhost/Calk/` path, you are making ajax call from `localhost/Workspace/Calk/` url, the original cookie is not visible here. Make your backend to not apply restrictions on the cookie path. – serg Apr 17 '16 at 18:14
  • I'm using java in backend. I've asked a question at [here](http://stackoverflow.com/questions/36594371) and I start 100 bounty 2 days ago. I become happy if you contribute. – Morteza Malvandi Apr 18 '16 at 03:44

1 Answers1

3

Set the following lines in Ext config:

Ext.Ajax.on("beforerequest",function(con){
  con.setUseDefaultXhrHeader(false);
  con.setWithCredentials(true);
});

So all of ajax requests will send cookie.

Narendra Jadhav
  • 9,619
  • 15
  • 29
  • 41
Dariush Jafari
  • 4,662
  • 6
  • 38
  • 66