skill-assessment-app/app/assets/javascripts/ajax-links.js

17 lines
594 B
JavaScript
Raw Normal View History

2016-09-15 10:01:31 -05:00
function handleAjaxResponse($el) {
var $header = $('header');
$el.on("ajax:success", function(e, data){
$header.after('<div class="success">' + data.message + '</div>');
}).on("ajax:error", function(e, xhr) {
if (xhr.status === 400){
$header.after('<div class="error">' + xhr.responseJSON.join('<br>') + '</div>');
} else {
$header.after('<div class="error">Oops! There was an error processing your request. Please try again.</div>');
}
});
}
$(document).ready(function() {
$('[data-id=ajax-action]').each(function(){ handleAjaxResponse($(this)); });
});