Search code examples
ajaxextjsextjs6setcookie

Cookie not set correctly in Extjs Ajax request


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?


Solution

  • 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.