Configuring the page loading and error messages

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.

Getting ready

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.

How to do it...

  1. In 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";
    });
  2. Create the #main page with the following content:
    <div data-role="content">
      <a href="/delay" data-role="button">Dummy page</a>
    </div>

How it works...

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:

How it works...

The error response causes the following error message to be shown:

How it works...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.5.86