EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Coder on August 28, 2021, 03:15:23 PM



Title: [SOLVED] datagrid & unexpected response from the server
Post by: Coder on August 28, 2021, 03:15:23 PM
how to intercept the answer from server before

API server periodically need to reauth and its answer something like the

Quote
{
"result":"error",
"error":"auth required"
}

and  datagrid do not event onLoadSuccess and do not event onLoadError :(
( in console: Uncaught TypeError: "Cannot read property 'length' of undefined" )

how to intercept this API server answer ?


UPD:

hmm ... in EasyUI 1.9.15 it turns out that neither 'onLoadSuccess' nor 'onLoadError' is ever called at all
Code:
 $('#DG').datagrid({
    ...
   ,onLoadError: function(){ console.log('DG load error'); }
   ,onLoadSuccess: function(aData){ console.log('DG load success',aData); }
   ...
currently possible only by overriding 'loader' ?


Title: Re: datagrid & unexpected response from the server
Post by: jarry on September 02, 2021, 11:15:29 PM
Please custom the 'loader' to achieve this functionality.

Code:
function loader(param, success, error){
var opts = $(this).datagrid('options');
if (!opts.url) return false;
$.ajax({
type: opts.method,
url: opts.url,
data: param,
dataType: 'json',
success: function(data){
if (data.result == 'error'){
error(data);
} else {
success(data);
}
},
error: function(){
error.apply(this, arguments);
}
});
}


Title: Re: datagrid & unexpected response from the server
Post by: Coder on September 16, 2021, 04:20:56 PM
Thnx!