Skip to content

Instantly share code, notes, and snippets.

@mech
Forked from db/jquery.ajax.progress.js
Created July 5, 2016 11:20
Show Gist options
  • Select an option

  • Save mech/c4dd04ffb432875abf04ced10f65dcc3 to your computer and use it in GitHub Desktop.

Select an option

Save mech/c4dd04ffb432875abf04ced10f65dcc3 to your computer and use it in GitHub Desktop.

Revisions

  1. Dean Burge revised this gist May 13, 2011. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions jquery.ajax.progress.js
    Original file line number Diff line number Diff line change
    @@ -18,14 +18,14 @@


    // usage:
    // note, if testing locally, size of file needs to be large enough
    // to allow time for events to fire

    $.ajax({
    url: "./json.js",
    type: "GET",
    dataType: "json",
    complete: function() {
    console.log("Completed.");
    },
    complete: function() { console.log("Completed."); },
    progress: function(evt) {
    if (evt.lengthComputable) {
    console.log("Loaded " + parseInt( (evt.loaded / evt.total * 100), 10) + "%");
  2. Dean Burge revised this gist May 13, 2011. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions jquery.ajax.progress.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    (function addXhrProgressEvent($) {
    var originalXhr = $.ajaxSettings.xhr;
    $.ajaxSetup({
    progress: function() { },
    progress: function() { console.log("standard progress callback"); },
    xhr: function() {
    var req = originalXhr(), that = this;
    if (req) {
    if (req.addEventListener || req.upload.addEventListener) {
    if (typeof req.addEventListener == "function") {
    req.addEventListener("progress", function(evt) {
    that.progress(evt);
    },false);
    @@ -16,18 +16,23 @@
    });
    })(jQuery);


    // usage:

    $.ajax({
    url: "./json.js",
    type: "GET",
    dataType: "json",
    complete: function() {
    console.log("Completed.");
    },
    progress: function(evt) {
    if (evt.lengthComputable) {
    console.log("Loaded " + parseInt( (evt.loaded / evt.totalSize * 100), 10) + "%");
    console.log("Loaded " + parseInt( (evt.loaded / evt.total * 100), 10) + "%");
    }
    else {
    console.log("Length not computable.");
    }
    }

    });
  3. Dean Burge revised this gist May 11, 2011. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion jquery.ajax.progress.js
    Original file line number Diff line number Diff line change
    @@ -14,4 +14,20 @@
    return req;
    }
    });
    })(jQuery);
    })(jQuery);

    // usage:

    $.ajax({
    url: "./json.js",
    type: "GET",
    dataType: "json",
    progress: function(evt) {
    if (evt.lengthComputable) {
    console.log("Loaded " + parseInt( (evt.loaded / evt.totalSize * 100), 10) + "%");
    }
    else {
    console.log("Length not computable.");
    }
    }
    });
  4. Dean Burge created this gist May 11, 2011.
    17 changes: 17 additions & 0 deletions jquery.ajax.progress.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    (function addXhrProgressEvent($) {
    var originalXhr = $.ajaxSettings.xhr;
    $.ajaxSetup({
    progress: function() { },
    xhr: function() {
    var req = originalXhr(), that = this;
    if (req) {
    if (req.addEventListener || req.upload.addEventListener) {
    req.addEventListener("progress", function(evt) {
    that.progress(evt);
    },false);
    }
    }
    return req;
    }
    });
    })(jQuery);