Skip to content

Commit

Permalink
Bug fix for ajax server side error.
Browse files Browse the repository at this point in the history
Signed-Off-By: Piyush Vijay <piyushvijay.1997@gmail.com>
  • Loading branch information
Piyush3079 committed Aug 17, 2018
1 parent 6594316 commit f2cc234
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
38 changes: 38 additions & 0 deletions js/src/ajax.js
Expand Up @@ -16,6 +16,9 @@ import { PMA_ensureNaviSettings,
} from './functions/navigation';
import { isStorageSupported } from './functions/config';
import PMA_MicroHistory from './classes/MicroHistory';
import { escapeHtml } from './utils/Sanitise';
import { PMA_sprintf } from './utils/sprintf';

/**
* This object handles ajax requests for pages. It also
* handles the reloading of the main menu and scripts.
Expand Down Expand Up @@ -757,13 +760,48 @@ export let AJAX = {
}
};

/**
* @todo Below mentioned two events and functions are added in this file as these
* events and functions are making ajax call to the server for fetching resources
* and data.
* For now there are are two jquery instances, one which is globally available in
* the window object and another which is being exported as module.
* Once all the code work on new imported jQuery instance, these events and functions
* can be copied to index.js
*/
/**
* Attach a generic event handler to clicks
* on pages and submissions of forms
*/
$(document).on('click', 'a', AJAX.requestHandler);
$(document).on('submit', 'form', AJAX.requestHandler);

$(document).ajaxError(function (event, request, settings) {
if (AJAX._debug) {
console.log('AJAX error: status=' + request.status + ', text=' + request.statusText);
}
// Don't handle aborted requests
if (request.status !== 0 || request.statusText !== 'abort') {
var details = '';
var state = request.state();
if (request.status !== 0) {
details += '<div>' + escapeHtml(PMA_sprintf(PMA_messages.strErrorCode, request.status)) + '</div>';
}
details += '<div>' + escapeHtml(PMA_sprintf(PMA_messages.strErrorText, request.statusText + ' (' + state + ')')) + '</div>';
if (state === 'rejected' || state === 'timeout') {
details += '<div>' + escapeHtml(PMA_messages.strErrorConnection) + '</div>';
}
PMA_ajaxShowMessage(
'<div class="error">' +
PMA_messages.strErrorProcessingRequest +
details +
'</div>',
false
);
AJAX.active = false;
AJAX.xhr = null;
}
});
/**
* @todo this is to be removed when complete code is modularised
* Exporsing module to window for use with non modular code
Expand Down
28 changes: 0 additions & 28 deletions js/src/index.js
Expand Up @@ -81,34 +81,6 @@ $(function () {
}
});

$(document).ajaxError(function (event, request, settings) {
if (AJAX._debug) {
console.log('AJAX error: status=' + request.status + ', text=' + request.statusText);
}
// Don't handle aborted requests
if (request.status !== 0 || request.statusText !== 'abort') {
var details = '';
var state = request.state();

if (request.status !== 0) {
details += '<div>' + escapeHtml(PMA_sprintf(PMA_messages.strErrorCode, request.status)) + '</div>';
}
details += '<div>' + escapeHtml(PMA_sprintf(PMA_messages.strErrorText, request.statusText + ' (' + state + ')')) + '</div>';
if (state === 'rejected' || state === 'timeout') {
details += '<div>' + escapeHtml(PMA_messages.strErrorConnection) + '</div>';
}
PMA_ajaxShowMessage(
'<div class="error">' +
PMA_messages.strErrorProcessingRequest +
details +
'</div>',
false
);
AJAX.active = false;
AJAX.xhr = null;
}
});

/**
* Adding common files for every page
*/
Expand Down

0 comments on commit f2cc234

Please sign in to comment.