Javascript 使用Dropzone'发送参数;ProcessQueue';事件
这是我的问题 我目前正在Laravel中构建一个应用程序,并使用DropZone为用户上传图像。现在在“新用户”页面上,我有用户详细信息和dropzone dropbox,这两个都是单独处理的 我将首先运行“createuser”方法,然后如果一切正常,上传图像 问题在于Dropzone在准备上载时不知道新用户Id(因为它需要在DB中分配给正确的用户) 我需要能够将新的用户Id传递回dropzone“processQueue”方法,以便在图像上载中使用新的用户Id,有人知道这是否可行吗 在一个完美的世界中,我将能够将新id传递到“processQueue”函数中,如Javascript 使用Dropzone'发送参数;ProcessQueue';事件,javascript,php,laravel,dropzone.js,Javascript,Php,Laravel,Dropzone.js,这是我的问题 我目前正在Laravel中构建一个应用程序,并使用DropZone为用户上传图像。现在在“新用户”页面上,我有用户详细信息和dropzone dropbox,这两个都是单独处理的 我将首先运行“createuser”方法,然后如果一切正常,上传图像 问题在于Dropzone在准备上载时不知道新用户Id(因为它需要在DB中分配给正确的用户) 我需要能够将新的用户Id传递回dropzone“processQueue”方法,以便在图像上载中使用新的用户Id,有人知道这是否可行吗 在一个完
processQueue(newUserId)
,然后获取它并将其添加到表单数据中,以便与图像一起发送
这是到目前为止我的代码
HTML
发送新用户请求,完成后发送图像
$.ajax({
type: "POST",
url: '/users',
data: postData,
success: function(data){
userProfile.processQueue(/* pass user id from here */);
},
error: function(data){
//Didnt work
}
});
一个选项是向保存id的Dropzone对象添加一个自定义属性,在ajax调用成功时设置该属性,然后在发送事件中访问该属性,相关部分是:
var userProfile = new Dropzone('#user_profile',{
...
userId: '', // Attribute to hold the user id
init: function(){
let thisDropzone = this; // Closure
...
this.on('sending', function(file, xhr, formData){
formData.append('userId', thisDropzone.userId);
});
}
});
ajax请求:
$.ajax({
type: "POST",
url: '/users',
data: postData,
success: function(data){
userProfile.userId = 'yourId'; // set the id
userProfile.processQueue(); // process queue
},
error: function(data){
//Didnt work
}
});
一个选项是向保存id的Dropzone对象添加一个自定义属性,在ajax调用成功时设置该属性,然后在发送事件中访问该属性,相关部分是:
var userProfile = new Dropzone('#user_profile',{
...
userId: '', // Attribute to hold the user id
init: function(){
let thisDropzone = this; // Closure
...
this.on('sending', function(file, xhr, formData){
formData.append('userId', thisDropzone.userId);
});
}
});
ajax请求:
$.ajax({
type: "POST",
url: '/users',
data: postData,
success: function(data){
userProfile.userId = 'yourId'; // set the id
userProfile.processQueue(); // process queue
},
error: function(data){
//Didnt work
}
});
太棒了,这完全有道理。我会尽快在我的代码上试用!谢谢,现在我们已经试过了,一切都很好。再次感谢!太棒了,这完全有道理。我会尽快在我的代码上试用!谢谢,现在我们已经试过了,一切都很好。再次感谢!