Fix AJAX POST redirects when session times out

Plus better redirect using JavaScript.