EasyUI Forum
April 28, 2024, 11:55:33 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: 'loader' attribute problem in panel  (Read 4974 times)
officecode
Jr. Member
**
Posts: 69


View Profile Email
« 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?
})
}
})

Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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);
}
});
},
Logged
officecode
Jr. Member
**
Posts: 69


View Profile Email
« Reply #2 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.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: December 27, 2018, 02:46:08 AM »

Please look at this example http://code.reloado.com/ejuveg4/edit#preview
Logged
officecode
Jr. Member
**
Posts: 69


View Profile Email
« Reply #4 on: December 27, 2018, 04:26:58 AM »

It seems that this should be my local server problem. Thank you!
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!