jquery/jquery-mobile — Issue #3143: Loading message is not hidden after using preventDefault in pageloadfailed event
Author: daniel-chambers
Created: 2011-11-23 00:24:34+00:00
State: open

If you listen to the pageloadfailed event and call event.preventDefault() (and later either data.deferred.success or .reject), the loading message is not hidden and stays on the page.

I have created a reproduction on jsfiddle here: http://jsfiddle.net/3PVpj/1/

When you click "Go to next page", jQuery will try to load a page that does not exist and fire the pageloadfailed event. I handle that event and call preventDefault and then call reject. You can see in the preview pane that the loading message sticks on the page and does not close.

I have reproduced this on jQuery Mobile 1.0 Final.

Looking at the jQuery Mobile code, it seems that the $.mobile.loadPage's ajax error function deliberately skips the hiding of the loading message when preventDefault is called. Unfortunately, there doesn't seem to be away to force close the loading message myself cleanly, because it is shown using a timer and the timer's handle is private to the loadPage function. The loadPage function uses a private function hideMsg to close the loading message, but it doesn't make that available for use by the handler of pageloadfailed. $.mobile.hidePageLoadingMsg can't be called directly as a workaround because it's possible it'll be called before the timer has actually displayed the message.