Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to add ajax loading icon in jquery

jQuery.fn.ajax = function(options)
{
    var $this = $(this);
    debugger;
    function invokeFunc(func, arguments)
    {
        if ( typeof(func) == "function")
        {
            func( arguments ) ;
        }
    }

    function _think( obj, think )
    {
        if ( think )
        {
            obj.html('<div class="loading" style="background: url(/public/images/loading_1.gif) no-repeat; display:inline-block; width:70px; height:30px; padding-left:25px;"> Loading ... </div>');
        }
        else
        {
            obj.find(".loading").hide();
        }
    }

    function makeMeThink( think )
    {
        if ( $this.is(".ajax-loading") )
        {
            _think($this,think);
        }
        else
        {
            _think($this, think);
        }
    }

    options = $.extend({}, options); // make options not null - ridiculous, but still.
    // read more about ajax events
    var newoptions = $.extend({
        beforeSend: function()
        {
            invokeFunc(options.beforeSend, null);
            makeMeThink(true);
        },

        complete: function()
        {
            invokeFunc(options.complete);
            makeMeThink(false);
        },
        success:function(result)
        {
            invokeFunc(options.success);
            if ( options.load )
            {
                $this.html(result);
            }
        }

    }, options);

    $.ajax(newoptions);
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: remove console messages of react-i18next 
Javascript :: nvm install a particular version 
Javascript :: assignment of struct in solidity 
Javascript :: jacascript loop array 
Javascript :: array name in id fields 
Javascript :: code ELIFECYCLE npm ERR! errno 126 
Javascript :: connect to local mongodb node 
Javascript :: forward slash in ajax url 
Javascript :: trim angular material input with ellipsis 
Javascript :: createSearchParams 
Javascript :: on click a button triger a tab bootstrap 5 
Javascript :: template.json replacing text in files 
Javascript :: ingore render on refresh page 
Javascript :: anonymous functions 
Javascript :: javascript replace url on sentence as achor 
Javascript :: javascript variable without value 
Javascript :: graphql get item by id from strapi react 
Javascript :: how to merge data rn 
Javascript :: jwt sign options 
Javascript :: display js variable in html without + 
Javascript :: dynamic array solidity 
Javascript :: resource loads fastest 
Javascript :: utterances reactjs 
Javascript :: get size of json array online 
Javascript :: promtail +verbose 
Javascript :: api dfetch data in reactjs 
Javascript :: Allowed Blocks in Nested Blocks Component Wordpress 
Javascript :: javascript for dummies 
Javascript :: is enabled 
Javascript :: javascript slider elementor 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =