Giter VIP home page Giter VIP logo

prokki-ajax's Introduction

Prokki Ajax

LICENSE LICENSE https://jquery.com/

This is a small javascript snippet to extend the default jQuery.ajax() function with an overlay while loading.

Integrations

Download the code from GitHub and copy the dist directory to your project.

Include the following lines of code in the <head> section of your HTML.

<link href="path/to/jquery.prokkiajax.min.css" rel="stylesheet" />
<script src="path/to/jquery.prokkiajax.min.js"></script>

The Basics

Since jQuery 3.0 the jQuerty.ajax() returns a jqXHR object which extends the chainable Deferred Object.

The methods success, complete and error are marked as deprecated, the deferred methods done, fail and always should be used instead.

Options

let pa = $.prokkiajax({
    overlay: "#ajax-loading",
    overlayAuto: true,
    spinner: "<i class=\"fa fa-spinner fa-spin fa-3x fa-fw\"></i><span class=\"sr-only\">Refreshing...</span>",
    minDuration: 500,
    beforeSend: null
});

Simple Usage

The ajax() is responsible for

  1. showing the overlay and
  2. excuting the asynchronous request.

In the deferred always method the overlay will be hidden.

let pa = $.prokkiajax({
    url: 'my_controller.php',
});

pa.ajax().always(pa.hideOverlay.bind(pa));

Extended Usage

let pa = $.prokkiajax({
    url: 'my_controller.php',
    beforeSend: function ()
    {
        console.log('Overlay is visible, but ajax request was not sent.');
    }
});

pa.ajax()
    .done(function ()
    {
        console.log('Method done: Overlay is still visible.');
    })
    .always(function ()
    {
        console.log('Method always I: Overlay is still visible.');
        
        pa.hideOverlay();
        
        console.log('Method always I: Overlay is removed.');
    })
    .always(function ()
    {
        console.log('Method always II: Overlay is removed');
    });

prokki-ajax's People

Contributors

prokki avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.