Fix regression from #152 when the server returns XML anyway

This commit is contained in:
Kijin Sung 2016-02-05 10:06:51 +09:00
parent ba50e81053
commit f902ea8c6f

View file

@ -115,9 +115,23 @@
// Define the error handler.
var errorHandler = function(xhr, textStatus) {
// If the server has returned XML anyway, convert to JSON and call the success handler.
if (textStatus === 'parsererror' && xhr.responseText && xhr.responseText.match(/<response/)) {
var xmldata = $.parseXML(xhr.responseText);
if (xmldata) {
var jsondata = $.parseJSON(xml2json(xmldata, false, false));
if (jsondata && jsondata.response) {
return successHandler(jsondata.response, textStatus, xhr);
}
}
}
// Hide the waiting message and display an error notice.
clearTimeout(wfsr_timeout);
waiting_obj.hide().trigger("cancel_confirm");
alert("AJAX communication error while requesting " + params.module + "." + params.act + "\n\n" + xhr.status + " " + xhr.statusText);
var error_info = xhr.status + " " + xhr.statusText + " (" + textStatus + ")";
alert("AJAX communication error while requesting " + params.module + "." + params.act + "\n\n" + error_info);
};
// Send the AJAX request.
@ -190,15 +204,16 @@
// If there was a success callback, call it.
if($.isFunction(callback_success)) {
clearTimeout(wfsr_timeout);
waiting_obj.hide().trigger("cancel_confirm");
callback_success(data);
}
};
// Define the error handler.
var errorHandler = function(xhr, textStatus) {
alert("AJAX communication error while requesting " + params.module + "." + params.act + "\n\n" + xhr.status + " " + xhr.statusText);
clearTimeout(wfsr_timeout);
waiting_obj.hide().trigger("cancel_confirm");
var error_info = xhr.status + " " + xhr.statusText + " (" + textStatus + ")";
alert("AJAX communication error while requesting " + params.module + "." + params.act + "\n\n" + error_info);
};
// Send the AJAX request.
@ -260,7 +275,8 @@
var errorHandler = function(xhr, textStatus) {
clearTimeout(wfsr_timeout);
waiting_obj.hide().trigger("cancel_confirm");
alert("AJAX communication error while requesting " + params.module + "." + params.act + "\n\n" + xhr.status + " " + xhr.statusText);
var error_info = xhr.status + " " + xhr.statusText + " (" + textStatus + ")";
alert("AJAX communication error while requesting " + params.module + "." + params.act + "\n\n" + error_info);
};
// Send the AJAX request.