Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
78 views
in Technique[技术] by (71.8m points)

javascript - FormData vs jQuery#serialize(), What is the difference?

Recently I was submitting a form using AJAX.

In researching the best method I saw some AJAX submissions using jQuery#serialize() and others using FormData. For example.

One submission did this:

data: $('form').serialize()

while the other did:

var formData = new FormData($('form')[0]);
data: formData

So what is the difference between FormData and jQuery#serialize()?

question from:https://stackoverflow.com/questions/33469684/formdata-vs-jqueryserialize-what-is-the-difference

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The main difference from a usage standpoint is that you can't serialize files, only file names....the value of a file input.

FormData object on the other hand also includes files if applicable.

Also serialize() will work in older browsers that don't support the FormData API for example IE < 10

reference FormData docs


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...