#900 add error option in exec_json, exec_html

This commit is contained in:
akasima 2014-08-13 11:21:03 +09:00
parent 5ca223ec2b
commit eb3da2617e
3 changed files with 165 additions and 65 deletions

View file

@ -1650,31 +1650,55 @@ function xml2json(xml, tab, ignoreAttrib) {
if(typeof(xeVid)!='undefined') $.extend(data,{vid:xeVid}); if(typeof(xeVid)!='undefined') $.extend(data,{vid:xeVid});
$.ajax({ try {
type: "POST", $.ajax({
dataType: "json", type: "POST",
url: request_uri, dataType: "json",
contentType: "application/json", url: request_uri,
data: $.param(data), contentType: "application/json",
success: function(data) { data: $.param(data),
$(".wfsr").hide().trigger('cancel_confirm'); success: function(data) {
if(data.error != '0' && data.error > -1000) { $(".wfsr").hide().trigger('cancel_confirm');
if(data.error == -1 && data.message == 'msg_is_not_administrator') { if(data.error != '0' && data.error > -1000) {
alert('You are not logged in as an administrator'); if(data.error == -1 && data.message == 'msg_is_not_administrator') {
if($.isFunction(callback_error)) callback_error(data); alert('You are not logged in as an administrator');
if($.isFunction(callback_error)) callback_error(data);
return; return;
} else { } else {
alert(data.message); alert(data.message);
if($.isFunction(callback_error)) callback_error(data); if($.isFunction(callback_error)) callback_error(data);
return; return;
}
} }
}
if($.isFunction(callback_sucess)) callback_sucess(data); if($.isFunction(callback_sucess)) callback_sucess(data);
} },
}); error: function(xhr, textStatus) {
$(".wfsr").hide();
var msg = '';
if (textStatus == 'parsererror') {
msg = 'The result is not valid JSON :\n-------------------------------------\n';
if(xhr.responseText === "") return;
msg += xhr.responseText.replace(/<[^>]+>/g, '');
} else {
msg = textStatus;
}
try{
console.log(msg);
} catch(ee){}
}
});
} catch(e) {
alert(e);
return;
}
} }
}; };
@ -1694,17 +1718,43 @@ function xml2json(xml, tab, ignoreAttrib) {
if(show_waiting_message) $(".wfsr").html(waiting_message).show(); if(show_waiting_message) $(".wfsr").html(waiting_message).show();
$.extend(data,{module:action[0],act:action[1]}); $.extend(data,{module:action[0],act:action[1]});
$.ajax({ try {
type:"POST", $.ajax({
dataType:"html", type:"POST",
url:request_uri, dataType:"html",
data:$.param(data), url:request_uri,
success : function(html){ data:$.param(data),
$(".wfsr").hide().trigger('cancel_confirm'); success : function(html){
self[type](html); $(".wfsr").hide().trigger('cancel_confirm');
if($.isFunction(func)) func(args); self[type](html);
} if($.isFunction(func)) func(args);
}); },
error: function(xhr, textStatus) {
$(".wfsr").hide();
var msg = '';
if (textStatus == 'parsererror') {
msg = 'The result is not valid page :\n-------------------------------------\n';
if(xhr.responseText === "") return;
msg += xhr.responseText.replace(/<[^>]+>/g, '');
} else {
msg = textStatus;
}
try{
console.log(msg);
} catch(ee){}
}
});
} catch(e) {
alert(e);
return;
}
} }
}; };

2
common/js/xe.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -414,31 +414,55 @@ function xml2json(xml, tab, ignoreAttrib) {
if(typeof(xeVid)!='undefined') $.extend(data,{vid:xeVid}); if(typeof(xeVid)!='undefined') $.extend(data,{vid:xeVid});
$.ajax({ try {
type: "POST", $.ajax({
dataType: "json", type: "POST",
url: request_uri, dataType: "json",
contentType: "application/json", url: request_uri,
data: $.param(data), contentType: "application/json",
success: function(data) { data: $.param(data),
$(".wfsr").hide().trigger('cancel_confirm'); success: function(data) {
if(data.error != '0' && data.error > -1000) { $(".wfsr").hide().trigger('cancel_confirm');
if(data.error == -1 && data.message == 'msg_is_not_administrator') { if(data.error != '0' && data.error > -1000) {
alert('You are not logged in as an administrator'); if(data.error == -1 && data.message == 'msg_is_not_administrator') {
if($.isFunction(callback_error)) callback_error(data); alert('You are not logged in as an administrator');
if($.isFunction(callback_error)) callback_error(data);
return; return;
} else { } else {
alert(data.message); alert(data.message);
if($.isFunction(callback_error)) callback_error(data); if($.isFunction(callback_error)) callback_error(data);
return; return;
}
} }
}
if($.isFunction(callback_sucess)) callback_sucess(data); if($.isFunction(callback_sucess)) callback_sucess(data);
} },
}); error: function(xhr, textStatus) {
$(".wfsr").hide();
var msg = '';
if (textStatus == 'parsererror') {
msg = 'The result is not valid JSON :\n-------------------------------------\n';
if(xhr.responseText === "") return;
msg += xhr.responseText.replace(/<[^>]+>/g, '');
} else {
msg = textStatus;
}
try{
console.log(msg);
} catch(ee){}
}
});
} catch(e) {
alert(e);
return;
}
} }
}; };
@ -458,17 +482,43 @@ function xml2json(xml, tab, ignoreAttrib) {
if(show_waiting_message) $(".wfsr").html(waiting_message).show(); if(show_waiting_message) $(".wfsr").html(waiting_message).show();
$.extend(data,{module:action[0],act:action[1]}); $.extend(data,{module:action[0],act:action[1]});
$.ajax({ try {
type:"POST", $.ajax({
dataType:"html", type:"POST",
url:request_uri, dataType:"html",
data:$.param(data), url:request_uri,
success : function(html){ data:$.param(data),
$(".wfsr").hide().trigger('cancel_confirm'); success : function(html){
self[type](html); $(".wfsr").hide().trigger('cancel_confirm');
if($.isFunction(func)) func(args); self[type](html);
} if($.isFunction(func)) func(args);
}); },
error: function(xhr, textStatus) {
$(".wfsr").hide();
var msg = '';
if (textStatus == 'parsererror') {
msg = 'The result is not valid page :\n-------------------------------------\n';
if(xhr.responseText === "") return;
msg += xhr.responseText.replace(/<[^>]+>/g, '');
} else {
msg = textStatus;
}
try{
console.log(msg);
} catch(ee){}
}
});
} catch(e) {
alert(e);
return;
}
} }
}; };