A post should work the same whether Ajax or regular PHP, so if you had a redirect in that controller method to redirect to login it should work. Test without using Ajax, get it working perfectly then test with AJAX it should work the same way.
Catch ajax if session has expired
Hi! In my view I have an ajax call like this:
$.ajax({
type: "POST",
url: "/savesomething",
async: false,
data: {message: "halllo"},
success : function(data) {
//show the success message
showMessage(data.message);
}
});
In my routes file I have a routes group and the route
Route::group(array('before' => 'auth'), function() {
Route::post('/savesomething', array('uses' => 'SomethingController@savesomething'));
}
Basically that works fine, but the problem is: What happens, if the user loads the site, then the session expires, and then through a user action the ajax post is fired. It does not reach my route because the route is within the route group which has the before "auth"-filter. The user isn't authenticated anymore, because the session has expired.
How can I catch this and redirect the user to my login site? I even have something like this at the end of my routes file:
App::missing(function($exception)
{
Log::info('This route is missing');
});
But still the ajax post seems to disappear somewhere... Thanks!
Please or to participate in this conversation.