EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Coder on March 29, 2021, 06:05:31 AM



Title: [SOLVED] datagrid with get method set cookie
Post by: Coder 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,
   ...
});


Title: Re: datagrid with get method set cookie
Post by: jarry 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);
}
});
}
})


Title: Re: [SOLVED] datagrid with get method set cookie
Post by: Coder on March 29, 2021, 07:22:54 PM
Thnx!