E
E
eldar_web2017-03-24 09:52:06
JavaScript
eldar_web, 2017-03-24 09:52:06

How to reload a page in an application (Ruby on Rails) after authorization expires if you render templates via ajax?

The Ruby on Rails application has a function that, before each request to the controller, checks whether the session has expired, and if so, sends it to the authorization page.
But there are moments in the application where we render templates via jquery+ajax: . So, after the expiration of the ajax request, the authorization page appears inside the requested template. How can (or correctly) reload the page? There is one option: for each ajax request, additionally check the session time from the server and make a decision, but I think this is not a good option, maybe this is the only option. $('element').load(url,data)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2017-03-24
@eldar_web

> the controller checks if the session has expired, and if yes, then we send it to the authorization page,
and if isset($_POST['ajax']), then we output an error/command, not a header
, and in js we check what ajax sent. if this is an authorization command, then we update the page (which will issue a header and send it to /login)
window.location.href=window.location.href

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question