使用Dropzone.js的非Ajax文章 [英] Non-ajax post using Dropzone.js

查看:146
本文介绍了使用Dropzone.js的非Ajax文章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何方法使Dropzone.js( http://dropzonejs.com )与标准浏览器POST配合使用的AJAX。

I'm wondering if there's any way to make Dropzone.js (http://dropzonejs.com) work with a standard browser POST instead of AJAX.

有些方法可以在提交之前将DOM中的input = file注入到DOM中?

Some way to inject the inputs type=file in the DOM right before submit maybe?

推荐答案

不。出于安全考虑,您不能手动设置< input type ='file'> 的值。当您使用Javascript拖放功能时,您完全超越了文件输入。一旦从用户的计算机获取文件,将文件提交到服务器的唯一方式是通过AJAX。

No. You cannot manually set the value of a <input type='file'> for security reasons. When you use Javascript drag and drop features you're surpassing the file input altogether. Once a file is fetched from the user's computer the only way to submit the file to the server is via AJAX.

解决方法:您可以将序列化文件或以其他方式进行字符串化并将其作为字符串附加到表单,然后在服务器端将其排序。

Workarounds: You could instead serialize the file or otherwise stringify it and append it to the form as a string, and then unserialize it on the server side.

var base64Image;
var reader  = new FileReader();
reader.addEventListener("load", function () {
    base64Image = reader.result;
    // append the base64 encoded image to a form and submit
}, false);
reader.readAsDataURL(file);

也许您正在使用dropzone.js,因为文件输入是丑陋和难以风格的?如果是这种情况,这个 Dropzone.js替代可能适用于您。它允许您创建可以使用表单提交的自定义样式输入。它支持拖放,但拖放您不能以所需的方式提交表单。 免责声明:我是上述图书馆的作者

Perhaps you're using dropzone.js because file inputs are ugly and hard to style? If that is the case, this Dropzone.js alternative may work for you. It allows you to create custom styled inputs that can be submitted with a form. It supports drag and drop too, but with drag and drop you cannot submit the form the way you want. Disclaimer: I am author of aforementioned library.

这篇关于使用Dropzone.js的非Ajax文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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