EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: officecode on December 26, 2018, 06:31:48 AM



Title: 'loader' attribute problem in panel
Post by: officecode on December 26, 2018, 06:31:48 AM
I encountered two problems when using the panel's loader property:

1)  If the url in ajax is wrong, how do I use the function 'error' and give an error message? I tried to solve it in the onLoadError event, but it didn't work.

2)  When using the loader, I must also set a url that is not empty, otherwise Ajax will not make a request.

These two questions are puzzling and ask for help. Thank you!
Here is the sample code:

Code:

$('#test').panel({
title: 'mytitle',
width: 300,
height: 100,
href:' ',     //The href attribute cannot be empty, otherwise the loader is invalid.
queryParams:{
v1:'abc'
},
loader:function(para,success,error){
$.get('test1.php',para,function(data){
success(data)
//If the request is wrong, how can I call the error function and give a prompt message?
})
}
})



Title: Re: 'loader' attribute problem in panel
Post by: stworthy on December 26, 2018, 07:03:26 PM
1. When the loading is error, the 'onLoadError' event fires.
Code:
$('#p').panel({
href: '_content1.html',
onLoad: function(){
alert('load ok')
},
onLoadError: function(){
alert('load error')
}
})

2. The is the default 'loader' definition, you can override it by yourself.
Code:
loader: function(param, success, error){
var opts = $(this).panel('options');
if (!opts.href){return false}
$.ajax({
type: opts.method,
url: opts.href,
cache: false,
data: param,
dataType: 'html',
success: function(data){
success(data);
},
error: function(){
error.apply(this, arguments);
}
});
},


Title: Re: 'loader' attribute problem in panel
Post by: officecode on December 27, 2018, 01:39:09 AM
Tested with this code, no matter what the href changes to, the 'onLoadError' event will not fire.


Title: Re: 'loader' attribute problem in panel
Post by: stworthy on December 27, 2018, 02:46:08 AM
Please look at this example http://code.reloado.com/ejuveg4/edit#preview


Title: Re: 'loader' attribute problem in panel
Post by: officecode on December 27, 2018, 04:26:58 AM
It seems that this should be my local server problem. Thank you!