How to handle page break errors in jQuery Mobile

I am writing a jQuery Mobile application that requires user authentication. The same user cannot open a session from several places: if the user logs in from another browser, the previous session is marked as dead.

If the user tries to go to another page with a browser with a dead session, the message "Page loading failed." This is bad because the user may not know why she is getting this error. Can I connect to the error event so that I can check the status of the session and redirect the user to the login page if the session is dead?

+6
source share
4 answers

I ended up deploying jQuery Mobile and added the ability to add a custom error handler: https://github.com/jquery/jquery-mobile/pull/2504 I think this is superior to other suggestions because it does not add any overhead except when an error actually occurs.

UPDATE: a new event will appear in jQuery Mobile RC1 with a pageloadfailed error. This will solve this problem elegantly and in accordance with the standards of the project.

+1
source

What about

pagechangefailed 

event?

It starts when the pageload error fails, which looks like this.

Additional information on http://jquerymobile.com/test/docs/api/events.html

+3
source

on this topic:

You can use something like

pagebeforeshow

Runs on the displayed page before the transition begins.

Example (pseudo code):

 $('#pageId').live('pagebeforeshow',function(event, ui){ // check session here if(!$session) { // redirect to login $.mobile.changePage('#login'); } }); 
+2
source
 $(a).click(function(){ // check for session? }); 
0
source

Source: https://habr.com/ru/post/897674/


All Articles