mercredi 15 juin 2016

pass additional parameters to jQuery's $.ajax() xhr callback


I'm doing this and it works splendidly

$.ajax({
    url : 'php/upload.php',
    xhr: function(){
        var xhr = new XMLHttpRequest();
        xhr.upload.addEventListener("progress", function (e) {
            $('#upload-progress-bar-1').animate({        
                'width': (Math.round(e.loaded / e.total) * 100) + '%'}, 400);
            }, false);
            return xhr;    
        },
        data : this.formData,
        type : 'POST',
        processData: false,
        contentType: false,
        dataType: "json",
        success : function(data) {
            //$('#upload-progress-bar-1').css('width', '100%');
        }
    });

The problem is that $('#upload-progress-bar-1') will be dynamic, but I can't figure out how to pass a parameter into the xhr: callback function.

Anyone know of a way of doing this?


Aucun commentaire:

Enregistrer un commentaire