将带有dropzone的其他数据发送到后端 [英] Send additional data with dropzone to the backend
问题描述
我正在尝试通过dropzone将图像文件的特定的已知位置ID发送到后端,该ID将被上传到服务器上.
尽管正在使用formData.append()
,但我没有看到任何内容.相反,仅显示了此"FormData {}
".
I am trying to send through dropzone a specific -already known- position ID of an image file to the backend, which is going to be uploaded on the server.
Although the formData.append()
is being used, I see that nothing is appended.Instead just this "FormData {}
" shows up.
dropzoneObject.on("sending", function(file, xhr, formData){
var nameOfFile = $(file.previewElement).find(".dz-filename").text();
var positionOfFile = fpos;
//console.log("The file who's being sent is named: "+nameOfFile+" and its position id is: "+positionOfFile);
formData.append("fpos", fpos);
});
我希望在示例中看到fpos = 16;
I expect to see in example fpos=16;
推荐答案
不知道您的特定错误,但这是一个简单的示例,说明如何使用jQuery使用dropzone发送其他数据并在后端使用php接收数据
Don't know about your particular error, but here is a simple example of how to send additional data with dropzone using jQuery and receiving it with php on the backend.
html:
<form id="myForm" class="dropzone"></form>
js:
Dropzone.autoDiscover = false;
$('.dropzone').dropzone ({
url: "upload.php",
init: function() {
this.on("sending", function(file, xhr, formData){
formData.append("fpos", 777)
}),
this.on("success", function(file, xhr){
alert(file.xhr.response);
})
},
});
成功事件仅用于说明如何访问从服务器发送的响应:
The success event is only to demonstrate how to access the response send from the server:
php:
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
echo "RECEIVED ON SERVER: \n";
echo "FILES: \n";
print_r($_FILES);
echo "\$_POST: \n";
print_r($_POST);
}
php只是将收到的相同数据发送回客户端,只是为了显示可访问的位置.
The php simply sends back to client the same data received, just to show where is accessible.
这篇关于将带有dropzone的其他数据发送到后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!