FormData与.serialize(),有什么区别? [英] FormData vs .serialize(), What is the difference?
问题描述
最近我使用AJAX提交表单。
Recently I was submitting a form using AJAX.
在研究最好的方法时,我看到一些使用 .serialize()
和其他人使用<$ c $提交的AJAX C> FORMDATA 。例如。
In researching the best method I saw some AJAX submissions using .serialize()
and others using FormData
. For example.
一次提交就是这样做的:
One submission did this:
data: form.serialize()
而另一个确实:
var formData = new FormData($('form')[0]);
data: formData
那么 FormData <之间有什么区别? / code>和
.serialize()
?
推荐答案
与使用角度的主要区别在于,您无法序列化文件,只能序列化文件名....文件输入的值
。
The main difference from a usage standpoint is that you can't serialize files, only file names....the value
of a file input.
FormData
另一方面,对象还包括文件(如果适用)。
FormData
object on the other hand also includes files if applicable.
同时 serialize()
将适用于不支持FormData API的旧浏览器,例如IE< 10
Also serialize()
will work in older browsers that don't support the FormData API for example IE < 10
参考 FormData文档
这篇关于FormData与.serialize(),有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!