JQuery Mobile Displays the Ajax loader manually, prompting for loading ...

Source: Internet
Author: User

When using jquery mobile development, sometimes we need to display the load prompt box during the request for Ajax (for example: a rotated picture + a hint: loading ... )。 This time, we can manually display the jquery mobile loader, the approximate process is as follows:

1. Boot loader, display "Loading ...";

2. Make an AJAX request, update the page data after the request is completed, and refresh the jquery mobile control style;

3. Close the loader.

Here's how to manually display the loader in jquery Mobile 1.2.0 and 1.1.0 (very simply, a few lines of code will be OK!). )。

The first is the jQuery Mobile 1.2.0 Reference:

[HTML]View Plaincopy
  2. <html>
  3. <head>
  4. <title>ajax test </title>
  5. <meta charset="GBK">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <!--from the official downloaded file in the project's Jquery-mobile directory --
  8. <link rel= "stylesheet" href="jquery-mobile/jquery.mobile-1.2.0.min.css"/>
  9. <link rel= "stylesheet" href= "jquery-mobile/jquery.mobile.structure-1.2.0.min.css " />
  10. <script src="Jquery-mobile/jquery-1.8.2.min.js"></script>
  11. <script src="Jquery-mobile/jquery.mobile-1.2.0.min.js"></script>
  12. <head>

Write JavaScript functions:

[JavaScript]View Plaincopy
  1. <script>
  2. Display Loader
  3. function Showloader () {
  4. //Display loader. For jQuery Mobile 1.2.0
  5. $.mobile.loading (' show ', {
  6. Text: ' loading in ... ', //loader display
  7. Textvisible: True, //Whether the text is displayed
  8. Theme: ' A ', //loader theme style A-e
  9. TextOnly: false, //Whether only text is displayed
  10. HTML: "" //HTML content to display, slices, etc.
  11. });
  12. }
  13. Hides the loader. For JQuery Mobile 1.2.0
  14. function Hideloader ()
  15. {
  16. //Hide Loader
  17. $.mobile.loading (' hide ');
  18. }
  19. </script>

Prepare two buttons, one for the launcher (display) loader, and one for the Stop (hide) Loader:

[HTML]View Plaincopy
  1. <body>
  2. <div data-role="page">
  3. <!--head --
  4. <div data-role="header">
  5. <h3>ajax test </h3>
  6. </div>
  7. <!--content --
  8. <div data-role="Content">
  9. <h3>ajax test </h3>
  10. <input type="button" value="show Ajax loader" onclick="Showloader ()"/>
  11. <input type="button" value="Hide ajax loader" onclick="Hideloader ()"/>
  12. </div>
  13. </body>

The effect is as follows (subject: ' A '):

Of course, you can adjust the $.mobile.loading (' show ', {...} Experiment with different loader effects in the parameters.

for details of the loader, see the jquery Mobile 1.2.0 official demo demo :


Note: The Ajax loader shown in JQuery Mobile1.1.0 is completely different from the 1.2.0 version! Hang Daddy!

The code for the JQuery Mobile 1.1.0 display loader is as follows:

[JavaScript]View Plaincopy
  1. <script>
  2. //Display loader
  3. function Showloader () {
  4. //Display loader. For jQuery Mobile 1.1.0
  5. $.mobile.loadingmessage = ' loading in ... '; //display of text
  6. $.mobile.loadingmessagetextvisible = true; //Whether to display text
  7. $.mobile.loadingmessagetheme = ' a '; //loader theme style A-e
  8. $.mobile.showpageloadingmsg (); //Display loader
  9. }
  10. //Hide loader. For jQuery Mobile 1.1.0
  11. function Hideloader () {
  12. //Hide Loader
  13. $.mobile.hidepageloadingmsg ();
  14. }
  15. </script>

The effect of the display is quite similar.

The description of 1.1.0 in the official 1.2.0 documentation is as follows:

The page Loading dialog is previously configured globally with three settings
$.mobile.loadingmessagetextvisible, and
Which is now deprecated. In addition to the methods for showing and hiding,
$.mobile.showpageloadingmsg and
$.mobile.hidepageloadingmsg is also deprecated.

This means: in 1.2.0, the $.mobile.showpageloadingmsg and $.mobile.hidepageloadingmsg are not used to display the loader.

Have questions welcome to the exchange of questions!

JQuery Mobile Displays the Ajax loader manually, prompting for loading ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.