handle ajax errors (closes foodcoops#300)
This commit is contained in:
parent
fa725dbf38
commit
d8f4ac47dd
2 changed files with 10 additions and 12 deletions
|
@ -116,18 +116,15 @@ $(function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show and hide loader on ajax callbacks
|
// Handle ajax errors
|
||||||
$('*[data-remote]').bind('ajax:beforeSend', function() {
|
// render json: {error: "can't except this!"}, status: :unprocessable_entity
|
||||||
$('#loader').show();
|
$(document).ajaxError(function(ev, xhr, settings, exception) {
|
||||||
});
|
try {
|
||||||
|
msg = xhr.responseJSON.error;
|
||||||
$('*[data-remote]').bind('ajax:complete', function() {
|
} catch(err) {
|
||||||
$('#loader').hide();
|
msg = I18n.t('errors.general');
|
||||||
});
|
}
|
||||||
|
alert(msg);
|
||||||
// Disable submit button on ajax forms
|
|
||||||
$('form[data-remote]').bind('ajax:beforeSend', function() {
|
|
||||||
$(this).children('input[type="submit"]').attr('disabled', 'disabled');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// The autocomplete attribute is used for both autocompletion and storing
|
// The autocomplete attribute is used for both autocompletion and storing
|
||||||
|
|
|
@ -3,6 +3,7 @@ translations:
|
||||||
- file: 'app/assets/javascripts/i18n/translations.js'
|
- file: 'app/assets/javascripts/i18n/translations.js'
|
||||||
only: [
|
only: [
|
||||||
'*.js.*',
|
'*.js.*',
|
||||||
|
'*.errors.*',
|
||||||
'*.number.*',
|
'*.number.*',
|
||||||
'*.date.formats.*',
|
'*.date.formats.*',
|
||||||
# foodsoft-specific texts to keep js with normal translations
|
# foodsoft-specific texts to keep js with normal translations
|
||||||
|
|
Loading…
Reference in a new issue