How To Show Loading Spinner In Ajax jQuery

Websolutionstuff | Jul-06-2022 | Categories : jQuery

In this article, we will see how to show loading spinner in ajax jquery. Using ajaxStart() and ajaxStop() method we can show loader on ajax call. When working with Ajax, showing a loading spinner or displaying a message with some animation like "Loading... Please Wait" is a popular way to indicate to the user that Ajax request is in progress. You can create a preloader using the jQuery ajaxStart() and ajaxStop() method.

So, let's see add loader in ajax call jquery, how to show loading in jquery, jquery loading spinner on ajax, show loader on ajax call jquery, ajax show loading, how to start/stop loader on every ajax call, jquery loading spinner on button click.

<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="utf-8">
    <title>How To Show Loading Spinner In Ajax jQuery - Websolutionstuff</title>
    <style>
        .overlay{
            display: none;
            position: fixed;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            z-index: 999;
            background: rgba(255,255,255,0.8) url("loader.gif") center no-repeat;
        }
        body.loading{
            overflow: hidden;   
        }
        body.loading .overlay{
            display: block;
        }
    </style>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script>
        $(document).on("click", "button", function(){
            $.get("customers.php", function(data){
                $("body").html(data);
            });       
        });

        $(document).on({
            ajaxStart: function(){
                $("body").addClass("loading"); 
            },
            ajaxStop: function(){ 
                $("body").removeClass("loading"); 
            }    
        });
    </script>
    </head>
    <body style="text-align: center;">
        <button type="button">Click Here...</button>
        <p>Click the above button to get the customers details from the web server via Ajax.</p>
        <div class="overlay"></div>
    </body>
</html>

 


You might also like:

Recommended Post
Featured Post
Datatables Show And Hide Columns Dynamically In jQuery
Datatables Show And Hide Colum...

In this article, we will see how to hide and show columns in datatable in jquery. This example shows how you can ma...

Read More

Jun-07-2022

How to Uninstall Composer on Ubuntu 23.04
How to Uninstall Composer on U...

Hey there! If you've found your way to this guide, chances are you're looking to bid farewell to Composer on you...

Read More

Jan-22-2024

How To Count Days Excluding Weekends And Holidays In Laravel 9
How To Count Days Excluding We...

In this article, we will see how to count days excluding weekends and holidays in laravel 9. Here, we will learn to...

Read More

Jan-24-2023

How To Generate QR Code In Angular 13
How To Generate QR Code In Ang...

In this article, we will see how to generate QR code in angular 13. In this example, we will use the angularx-qrcod...

Read More

Jun-09-2022