jquery file upload module sending extra parameter

2019-07-27 22:15发布

I'm using jquery file upload plugin. I added an extra button to tell the server to finalize everything, this is suppose to send an extra parameter as below:

$('.btn-finalize').click(function(){
    $('#fileupload').fileupload({
        dataType:'json',
        formData:{name:'finalize',value:'1'},
        url: 'server/php/'
       });
});

This click handler is called, but no request is getting sent. why?

1条回答
够拽才男人
2楼-- · 2019-07-27 22:55

The documentation advice to inverse click and autoupload handlers.

$('#fileupload').fileupload({
    autoUpload: false,
    formData: {
        name: 'finalize',
        value: '1'
    },
    add: function (e, data) {
        $('.btn-finalize').click(function () {
            data.submit();
        })
    },
    done: function (e, data) {    
        console.log(data.formData.name); // Show "finalize" in the console
    }
});

A testing fiddle

查看更多
登录 后发表回答