更新时间:2022-12-11 16:32:46
现在的问题是,你不能把同样的方式作为普通的文本字段文件中的字段。
The problem is that you can't treat file fields in the same manner as regular text fields.
当你调用 $('输入')。VAL()
,你得到的文本字段中的实际文本值,但该文件字段,你得到的文件名称 - 而不是文件内容
When you call $('input').val()
, you get an actual text value for the text field, but for the file field you get the file name - and not the file contents.
那么你的脚本试图验证文件名的文件,显然,失败。为了让文件验证器,您需要有实际的文件内容传递给脚本成功。
Then your script tries to validate your file name as a file and, apparently, fails. In order for file validator to succeed you need to pass actual file contents to the script.
所以,基本上,你需要异步上传文件到服务器进行所有必要的验证。
So, basically, you need to upload a file asynchronously to the server to perform all the necessary validations.
不幸的是,通过Ajax上传的文件,并不是一个简单的事情。你的基本选项是通过的iFrame
上传文件或 SwfObject的
。你可以看看的广泛选择合适的插件用于这一目的here.
Unfortunately, uploading files via Ajax is not quite a trivial thing to do. Your basic options are uploading files via iFrame
or swfObject
. You can take a look at the broad selection of plugins suitable for this purpose here.
异步文件上传我个人的选择是文件上传的jQuery插件。
My personal choice for asynchronous file upload would be file-uploader jQuery plugin.