0

i have developed complete application but i need to handle the session time out in ajax call so need to check ajax response in all methods. i need alternative for that. i used ajaxcomplete method but it calls after success. so Is there any method which get called before success?

Ravi
  • 316
  • 7
  • 17
  • 1
    Can you share whatever code you have done so far ? – Himanshu Upadhyay Sep 22 '17 at 12:09
  • I think here is what you are looking for https://stackoverflow.com/questions/21648356/jquery-ajax-beforesend-and-success-error-complete – Nikhil Parmar Sep 22 '17 at 12:09
  • Assuming the request made after session timeout fails, you should return an error HTTP status code from the request. 401 would make the most sense. You can then check the error code in jQuery and act appropriately – Rory McCrossan Sep 22 '17 at 12:10
  • http://api.jquery.com/category/ajax/global-ajax-event-handlers/ has all the `Global Ajax Event Handlers`. However I'm not 100% sure if that is what you are looking for. – Jonas Osburg Sep 22 '17 at 12:11
  • yes @RoryMcCrossan i have checked the status code and redirected to the login page. But Complete method call after the success method in that case the code in the success method get excuted. – Ravi Sep 22 '17 at 12:12
  • @RoryMcCrossan But Complete method calls after the success method in that case the code in the success method get excuted. and rediction to login happen after that so i dont want to excute code in the success. is there any way? – Ravi Sep 22 '17 at 12:14
  • @JonasSchwabe i handled the session time out but don't want to excute my success code, i want to immediately get redicted to login. – Ravi Sep 22 '17 at 12:16
  • 1
    When your session is not valid, your application should send a 4xx (usually 401 or 403) http status. In this case the success handler would not be called at all. – Jonas Osburg Sep 22 '17 at 12:20
  • @JonasSchwabe i tried that, when i try to return 401, i get 500 in ajax request,i don't understand why this happen – Ravi Sep 22 '17 at 12:22

1 Answers1

2

Yes & it's the ajaxSend() global event handler, see the following image that I captured from the lynda.com course presented by Joe Marini

enter image description here

Mehdi Bouzidi
  • 1,937
  • 3
  • 15
  • 31