BlueImp:如何在destroy事件上设置和发送额外的formData?

时间:2016-05-19 10:53:03

标签: jquery jquery-file-upload blueimp

发布表单数据时,我的后端还需要来自_csrfToken字段的数据。如何在用户单击以删除BlueImp jQuery插件上的图像时设置和发送此字段数据?

以下是我没有成功的尝试,following BlueImp Docs

  $('#fileupload').on('fileuploaddestroy', function (e, data) {
    var val = $('input[name="_csrfToken"]').val();
    data.formData = {_csrfToken: val};
    });

我在chrome开发人员工具中看到的内容

Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:hr
Connection:keep-alive
Content-Length:0
Cookie:csrfToken=7fb73d62278fe3773c07ce1668f0af107d57a9bcdf7f2e1565dd8836907c9141c8ed9db2507636e5de7b8e6d9f6cdce3065b5d48100dd6b37d85568c3d8d0b89; CAKEPHP=l32oplq1i7qfapv3vtr6up7au1
Host:localhost
Origin:http://localhost
Referer:http://localhost/apartmani/admin/albums/edit/1
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
X-Requested-With:XMLHttpRequest

1 个答案:

答案 0 :(得分:0)

好的,我通过设置标题找到解决方案:

 $('#fileupload').on('fileuploaddestroy', function (e, data) {
    var val = $('input[name="_csrfToken"]').val();
    //data.formData = {_csrfToken: val};
    data.headers={'X-CSRF-Token': val};
    });