EasyUI Forum
May 01, 2024, 08:57:01 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] datagrid with get method set cookie  (Read 3604 times)
Coder
Jr. Member
**
Posts: 96


View Profile
« on: March 29, 2021, 06:05:31 AM »

Hi!

how to enable set cookie in datagrid (withCredentials:true in ajax request) ?


Code:
  <table id="dg" noheader="true" fit="true" class="easyui-datagrid" 
            url="${API_PATH}?$API_CMD"
            pagination="false"
            idField="ID"
            rownumbers="true" fitColumns="true" singleSelect="true" showFooter="false"
  >
    <thead>
...
    </thead>
  </table>

basic ajax will be:
Code:
jQuery.ajax({
    type: "GET",
    xhrFields: {withCredentials: true},  // <---
    url: myURL,
   ...
});
« Last Edit: March 29, 2021, 07:22:40 PM by Coder » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: March 29, 2021, 07:18:16 PM »

The simplest way to solve this issue is to setup the parameters globally.
Code:
$.ajaxSetup({crossDomain: true, xhrFields: {withCredentials: true}});

You also can override the default loader function of the datagrid component.
Code:
$.extend($.fn.datagrid.defaults, {
loader: function(param, success, error){
var opts = $(this).datagrid('options');
if (!opts.url) return false;
$.ajax({
type: opts.method,
url: opts.url,
xhrFields: {withCredentials: true},
data: param,
dataType: 'json',
success: function(data){
success(data);
},
error: function(){
error.apply(this, arguments);
}
});
}
})
Logged
Coder
Jr. Member
**
Posts: 96


View Profile
« Reply #2 on: March 29, 2021, 07:22:54 PM »

Thnx!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!