0

I need to check whether or not a user is logged in or not based on a session. I know there are other ways like setting setInterval, etc to get this data back, but what I'm wondering is there a way to see the data requested back from a ajax request on a global scale such as:

$(document).ajaxStop(function(){ //show data });

I'm wondering this specifically because I have all my ajax calls on the front end being filtered through one method on the server side and in that method, I'm just returning a variable if the session is dead. I'd much rather be able to check that variable from one place rather than have to check it in every method before throwing a session error.

Is this possible or is there a way to retrieve the data through the global request?

jamadri
  • 926
  • 3
  • 17
  • 32
  • 1
    check for `xhr.responseJSON` in `ajaxSuccess` ... will not be truthy if dataType is html, xml or text **https://jsfiddle.net/1orxvwue/**. Or check response headers if that is how you identify login status – charlietfl Apr 14 '17 at 16:35
  • 1
    Or perhaps better ajaxComplete if you don't return 200 status – charlietfl Apr 14 '17 at 16:42
  • @charlietfl Thank you! xhr was undefined based on success but adding the ajaxComplete instead allowed my xhr response to come through clean. This is exactly what I was looking for! – jamadri Apr 14 '17 at 16:49

0 Answers0