如何使JQuery的文件上传在上传的所有文件插件调用后端只有一次? [英] How to make JQuery file upload plugin call backend only once for all the files in an upload?

查看:293
本文介绍了如何使JQuery的文件上传在上传的所有文件插件调用后端只有一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用sails.js建立一个网站。我有一个名为模型时间表。它有一些文本域的命名集合图片一起。每个时间表可以有多个图片。我想一次,当用户点击保存更新所有这些领域。我使用jQuery文件上传,以帮助多文件上传。

I'm using sails.js to build a website. I have a model named timeline. It has some text fields along with a collection named pictures. Each timeline can have multiple pictures. I want to update all these fields at once when user clicks save. I'm using JQuery file uploader to help multifile upload.

问题是,JQuery的文件上传调用我的后端文件上传服务,一次上载的每个图片。我需要更新其他文本字段只有一次,他们需要记录获得创建,因为每个画面都需要有一个时间轴中的图片之前更新与之关联的ID。

Problem is, JQuery file upload calls my backend file-uploader service once for each picture uploaded. I need to update the other text fields only once and they need to be updated before the pictures records get created since each picture needs to have a timeline ID associated with them.

时的异步任务,要走的路?我不觉得如此以来,JQuery的文件上传调用我的后端多次,我不认为我可以把任务和使用异步并行更新等领域。我已经做到了,如果它是一个单一的呼叫上传。

Is async tasks the way to go? I don't feel so since JQuery file uploader calls my backend multiple times, I don't think I can push the tasks and update other fields using async parallel. I could've done it if it were a single call to upload.

我想保持两个提交按钮的 - 一个文本字段,一个用于文件上传,但真的没有preFER这种方式。如果有人指导我这将是巨大的。

I'm thinking of keeping two submit buttons - one for text fields and one for file uploads but really don't prefer this way. It would be great if anyone guides me on this.

推荐答案

设置 SingleFileUploads 为false并没有多大帮助的jQuery文件上传,因为似乎有一个bug如以上所讨论。所以我设置的事情回到正确的。

Setting SingleFileUploads to false didn't help much with JQuery file uploader since there seems to be a bug as discussed above. So I set that thing back to true.

我分开输入成两个独立的形式 - 一个文本字段输入和一个用于文件(经过的JQuery文件上传)。对于文本字段组成,我一直在一个可见的按钮,用户可以点击。至于其他的,我躲在按钮。因此,一旦用户点击可见的按钮,我只提交了文字输入,并在后台创建数据库记录(这是使用AJAX调用来完成),并在成功字段AJAX调用的,我。点击()隐藏的按钮,如果文件数大于0。

I separated the inputs into two separate forms - one for text fields input and one for files(which goes through JQuery file uploader). For the text fields form, I kept a visible button the user can click. For the other one, I hid the button. So once the user clicks the visible button, I submit only the text input and create a database record in the backend(this is done using an AJAX call) and in the success field of AJAX call, I .click() the hidden button if the file count is more than 0.

这篇关于如何使JQuery的文件上传在上传的所有文件插件调用后端只有一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆