makkus makkus - 3 months ago 13
Javascript Question

My ajax process is repeating at dropzone js

I need some detail with image in the database. I am using dropzone js for upload. Problem happening when I execute more than one to ajax. After the first execute, each time its adding same data once again. dropzone working correctly

e.g
first post adding one data -
second post adding two data -
third post adding three data

Dropzone.options.seferekle = {
paramName: "file",
parallelUploads : 1,
acceptedFiles: '.jpg,.jpeg,.JPEG,.JPG,.png,.PNG',
autoProcessQueue : false,
addRemoveLinks : true,
init: function() {

myDropzone = this;

$('.post').on('click', function(event){

tarih = $("input[name=tarih]").val();

if(!tarih)
{
alert("Sefer Tarihi ve Sefer Türü Alanları Boş Bırakılamaz.");
}
else
{
myDropzone.processQueue();

myDropzone.on("success", function(file, responseText) {
newImgName= responseText;

$.ajax({
url: "http://localhost/vipumre/App/Model/add.php",
data: "image_name="+newImgName+"&tarih="+tarih,
type: "post",

success: function(data) {
$('.return').show();
$('.return').text(data);
},

error: function() {
$('.return').show();
$('.return').text("Ajax Error");
}

}); //Ajax End

myDropzone.on("complete", function(file,done) {
this.removeAllFiles(true);
done();
})

});

}

});

} //Dropzone init End

}; //Dropzone End

Answer

If you want to send data while you uploading your files you should use the sending event :

Dropzone.options.seferekle = {

    init: function (e) {

        var myDropzone = this;

        // Event to send your custom data to your server
        myDropzone.on("sending", function(file, xhr, data) {

            // First param is the variable name used server side
            // Second param is the value, you can add what you what
            // Here I added an input value
            data.append("your_variable", $('#your_input').val());
        });

    }
};
Comments