Skip to content Skip to sidebar Skip to footer

Ajax Loading Bar Function

I know there are a few post about this but they dont cover what i need to achieve. I'm trying to get the youtubelike loading bar to work properly. And i found this : var data = [];

Solution 1:

It's late to reply, but its worth to share some knowledge, so others may get help from it.

You can extend jQuery AJAX XHR object as below.

jQuery.ajaxSettings.xhr = function ()
{
    var xhr = newwindow.XMLHttpRequest();
    //Upload progress
    xhr.upload.addEventListener("progress", function (evt) {
        if (evt.lengthComputable) {
            var percentComplete = evt.loaded / evt.total;
            //Do something with upload progressconsole.log('percent uploaded: ' + (percentComplete * 100));
        }
    }, false);
    //Download progress
    xhr.addEventListener("progress", function (evt) {
        if (evt.lengthComputable) {
            var percentComplete = evt.loaded / evt.total;
            //Do something with download progressconsole.log('percent downloaded: ' + (percentComplete * 100));
        }
    }, false);
    return xhr;
}

Post a Comment for "Ajax Loading Bar Function"