jQuery:FormData()不起作用 [英] jQuery: FormData() doesn't work

查看:397
本文介绍了jQuery:FormData()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我举了一个非常简单的示例来测试jQueryFormData是否起作用.

I made a really really simple example to test whether jQuery's FormData work or not.

html

<form id="frm" action="/fileupload" method="post">
<input type="file" name="uploadfile" />
<input type="file" name="uploadfile" />
<input type="button" id="uploadbutton" value="클릭" />
</form>

然后导入jQuery cdn:

<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>

我从计算机中选择了一些图像文件.

I select some image file from my computer.

并在Chrome development tool中执行以下代码:

>> var form = $('#frm');
>> form

<form id="frm" action="/fileupload" method="post">
<input type="file" name="uploadfile" />
<input type="file" name="uploadfile" />
<input type="button" id="uploadbutton" value="클릭" />
</form>


>> var formData = new FormData(form);
>> formData

它显示的只是

FormData {}

它不包含任何值.它是空的.为什么它不起作用?

It doesn't contain any values. It was empty . Why does it not work?

推荐答案

我认为,您应该尝试传递元素本身,而不传递jQuery对象:

I reckon, you should try passing the element itself, but not the jQuery object:

var formData = new FormData(form[0]);

这篇关于jQuery:FormData()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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