ilopx/jquery-ajax-progress

Simple patch that adds a 'progress' callback to jquery Ajax calls

Installs: 10

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 83

Language:JavaScript

1.2.1 2015-08-23 21:57 UTC

This package is not auto-updated.

Last update: 2024-05-15 09:14:18 UTC


README

A simple patch to jQuery that will call a 'progress' callback, using the XHR.onProgress event

Video demo

Video Demo

Install and use

a. CDN

jquery.ajax-progress.js or jquery.ajax-progress.min.js

Include the script on your page:

<script src="https://cdn.rawgit.com/ilopX/jquery-ajax-progress/master/dist/jquery.ajax-progress.js"></script>

or

<script src="https://cdn.rawgit.com/ilopX/jquery-ajax-progress/master/dist/jquery.ajax-progress.min.js"></script>

b. Install

bower install ilopx-jquery-ajax-progress
composer require ilopx/jquery-ajax-progress

Use simple template script

template.js

$(function() {
    $.ajax({
        method: 'GET',
        url: '', // TODO: add url
        data: {
            // TODO: add data
        },
        success: function() {
            // TODO add message all ok
        },
        error: function() {
            // TODO add message error
        },
        progress: function(e) {
            if(e.lengthComputable) {
                var progress = e.loaded / e.total * 100;
                var content = e.srcElement.responseText;
            }
            else {
                // TODO add message error 'Content Length not reported!';
            }
        }
    });
});

Notes