I'm writing a jQuery Mobile application that requires user authentication. The same user cannot have her session open from multiple locations: if user logins from another browser, the previous session is marked as dead.
If the user attempts to move to another page with the browser with the dead session, "Error loading page" message is displayed. This is bad because user might not know why she's getting this error. Is it possible to tap in to the error event so I could check for the status of the session and redirect user to the login page if the session is dead?
Description: Programmatically change from one page to another. Note: jQuery.mobile.changePage is deprecated as of jQuery Mobile 1.4.0 and will be removed in 1.5.0. Use the pagecontainer widget's change () method instead.
A common error is when AJAX returns no data. This can be handled by adding error messages, see the following example of an AJAX contact form. Checking in firebug the has a StatusText field which can be used to determine the type of jQuery error.
By default, changePage () ignores requests to change to the current active page. Setting this option to true, allows the request to execute. Developers should note that some of the page transitions assume that the fromPage and toPage of a changePage request are different, so they may not animate as expected.
Used only when the 'to' argument of changePage () is a URL. Programmatically change from one page to another. This method is used internally for the page loading and transitioning that occurs as a result of clicking a link or submitting a form, when those features are enabled.
How about the
pagechangefailed
event?
It is fired when the pageload fails, which seems to be the case.
More info on http://jquerymobile.com/test/docs/api/events.html
Related:
You could use something like
pagebeforeshow
Triggered on the page being shown, before its transition begins.
Example (pseudo code):
$('#pageId').live('pagebeforeshow',function(event, ui){
// check session here
if(!$session) {
// redirect to login
$.mobile.changePage('#login');
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With