0

I have a mobile application that I'm trying to force a redirect to the login page on a 401 ajax call; however what seems to be happening is that jQM is trying to load this via AJAX as the request is sent.

This does work for safari and firefox devices but does not work with Chrome, yet to test on an IE device.

$(function() {
  $.ajaxSetup({
    statusCode: {
      401: function() {
        console.debug("User is not authenticated");
        window.location.href = core.getUrl('/login');
      }
    }
  });
});

UPDATE: Meant that it does not work on chrome, firefox is actually okay.

Brett Ryan
  • 26,937
  • 30
  • 128
  • 163
  • 1
    I think window.location.href does not work in jQuery mobile, did you try using some sort of changePage() instead of ajax? or document.location.href instead of window? there are some topics on this: http://stackoverflow.com/questions/7449402/jquery-mobile-mobile-changepage-not-loading-external-js-files / http://forum.jquery.com/topic/mobile-changepage-and-rel-external – dotchuZ Sep 24 '13 at 05:37
  • zyrex, `document.location.href` seems to have solved the problem. – Brett Ryan Sep 24 '13 at 23:37
  • give it at least an upvote for thanking :D – dotchuZ Sep 25 '13 at 10:42
  • @zyrex I had already upvoted. Make it an answer and I can accept that. – Brett Ryan Sep 25 '13 at 19:56

1 Answers1

0

I dont see any problem in your ajax call. but I think there is a problem in core.getUrl('/login'); can you print out when core.getUrl('/login'); generates?

Laxman
  • 1,149
  • 2
  • 11
  • 17
  • `core.getUrl('/login')` is working fine and gets `http://localhost:8084/context23/login`. I can see that it's working fine as in the Firebug debugger the actual page is retrieved through jquery instead of the actual page being changed, the correct page content is being loaded. – Brett Ryan Sep 24 '13 at 03:11
  • try by adding location.reload(); after window.locaiton.href. – Laxman Sep 24 '13 at 15:34