By default, the jQuery Mobile framework shows a spinning animation with theme a
and without any text when loading a new page. If there is an error, the page load times out and an error message Error Loading Page
is shown, with theme e
. This recipe shows you how to change and customize the page loading and error messages.
Copy the full code of this recipe from the sources code/07/load-message
folder. To try out this recipe, launch the simple nodejs
web server that is available in the folder code, by using the following command:
node jqmserver.js
Then you can launch the code by using the URL: http://localhost:8080/07/load-message/main.hml
.
main.html
, add the following script before including jquery.mobile.js
:$(document).bind("mobileinit", function() { $.mobile.loadingMessage = "Fetching it..."; $.mobile.loadingMessageTextVisible = true; $.mobile.loadingMessageTheme = "b"; $.mobile.pageLoadErrorMessage = "Oops, it's missing!"; $.mobile.pageLoadErrorMessageTheme = "b"; });
#main
page with the following content:<div data-role="content">
<a href="/delay" data-role="button">Dummy page</a>
</div>
Create main.html
, and add the given script before including the reference to jquery.mobile.js
. In the script, add an event handler for the mobileinit
event that gets triggered at the start of the app. Here, set the default page load messages and error messages as shown in the code.
In #main
, there is a link that tries to open the "/delay"
page. This is a GET
operation on the nodejs
server. The server handles this request and returns an error code after pausing for a few seconds. The spin control with a text message is shown for this duration, as shown in the following screenshot:
The error response causes the following error message to be shown:
18.217.5.86