• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Adding this Progress Bar script code to existing upload code


Bronze Coder
I am looking for assistance with how to integrate this Progress Bar script code to my successfully working upload code. Here's the progress bar script code:

    // File upload via Ajax
    $("#uploadForm").on('submit', function(e){
            xhr: function() {
                var xhr = new window.XMLHttpRequest();
                xhr.upload.addEventListener("progress", function(evt) {
                    if (evt.lengthComputable) {
                        var percentComplete = ((evt.loaded / evt.total) * 100);
                        $(".progress-bar").width(percentComplete + '%');
                }, false);
                return xhr;
            type: 'POST',
            url: 'upload.php',
            data: new FormData(this),
            contentType: false,
            cache: false,
            beforeSend: function(){
                $('#uploadStatus').html('<img src="images/loading.gif"/>');
                $('#uploadStatus').html('<p style="color:#EA4335;">File upload failed, please try again.</p>');
            success: function(resp){
                if(resp == 'ok'){
                    $('#uploadStatus').html('<p style="color:#28A74B;">File has uploaded successfully!</p>');
                }else if(resp == 'err'){
                    $('#uploadStatus').html('<p style="color:#EA4335;">Please select a valid file to upload.</p>');

And here is my existing, successfully working upload code:

        function uploadFile() {
            // create FormData
          var fileType = 'video'; // or "audio"
          var fileName = 'vid.webm';
          var formData = new FormData();
          var request = new XMLHttpRequest;
          formData.append(fileType + '-filename', fileName);
          formData.append(fileType + '-blob', blob);
          request.open("POST", "/save1.php");

         request.onreadystatechange = function() {
         if(request.readyState==4) {


Any assistance is appreciated

New Threads

Buy us a coffee!

Top Bottom