I am trying to use flash('error', 'error text')
to alert the webpage that an error has occurred via an ajax request. The ajax request hits an action where some database work is involved, and an error could be produced.
Controller:
load('application');
action('index', function() {
this.title = 'Sample Page';
render();
});
action('test', function() {
flash('error', 'test error message');
render('index', { title: 'Sample Page' });
});
Sample ajax call:
$.ajax({
url: '/test-error',
success: function(response) {
console.log(response);
},
error: function(response) {
console.log(response);
}
});
Routes:
map.get('test', 'test-error#index');
map.get('test-error', 'test-error#test');
Is this even possible through an ajax call? I've tried using flash
, followed by render('index')
as shown above and have tried redirect(path_to.test);
with no success. send(500, 'error message');
returns an error to the ajax call, which, if necessary, I could reload the page from there.