跨域文件上载时出现Dropzone错误

时间:2017-07-07 14:56:50

标签: javascript php jquery dropzone.js

我想通过 dropzone 将文件从服务器上传到其他服务器。但我一直在犯错误Server responded with 0 code。 Dropzone仅向目标服务器发送Option请求。请求和响应标头在这里。之后我得到error('0 code'); 我还将Headers设置为我的PHP脚本。这些是什么。

header('Access-Control-Allow-Origin: '.$pathToOrigin);
header('Access-Control-Allow-Credentials:false');
header('Access-Control-Max-Age:1000');
header('Access-Control-Allow-Methods:PUT, POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: X-Requested-With, cache-control, content-type, access-control-allow-origin, access-control-allow-methods, access-control-allow-headers');

requuest headers

2 个答案:

答案 0 :(得分:0)

尝试以下操作,我将您的发送功能更新为:

  method: 'put',
  this.on("sending", function(file, xhr, formData) {
    formData.append('k1', $('#k1').val());
    var _send = xhr.send;
    xhr.send = function() {
      _send.call(xhr, file);
    }
  });



$("div#drop").dropzone({
  method: 'put',
  url: "<?php echo $pathToUploadFiles ?>",
  autoProcessQueue: false,
  addRemoveLinks: true,
  this.on("sending", function(file, xhr, formData) {
    formData.append('k1', $('#k1').val());
    var _send = xhr.send;
    xhr.send = function() {
      _send.call(xhr, file);
    }
  });
  success: function(file) {
    this.removeFile(file);
  },
  queuecomplete: function() {
    toastr.info("Files are Uploaded Successfully!");
  }
});
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我试过把methode太多了。同样的回答。浏览器只发送(选项)请求。这是浏览器响应的图像。 Image of Response