gpt4 book ai didi

javascript - 跨域文件上传时出现 Dropzone 错误

转载 作者:行者123 更新时间:2023-11-28 04:26:53 26 4
gpt4 key购买 nike

我想使用 dropzone 将文件从服务器上传到其他服务器。但我不断收到错误服务器响应 0 代码。 Dropzone仅向目标服务器发送Option请求。请求和响应 header 都在这里。之后我收到 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

最佳答案

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

  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!");
}
});

关于javascript - 跨域文件上传时出现 Dropzone 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44973907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com