Skip to content

Commit 7b7f9fa

Browse files
committed
Add support for file input fields
1 parent 7f5764c commit 7b7f9fa

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

jquery.pjax.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,24 @@ function handleSubmit(event, container, options) {
125125
var defaults = {
126126
type: form.method.toUpperCase(),
127127
url: form.action,
128-
data: $(form).serializeArray(),
129128
container: $(form).attr('data-pjax'),
130129
target: form
131130
}
132131

132+
if (window.FormData !== undefined) {
133+
defaults.data = new FormData(form);
134+
defaults.processData = false;
135+
defaults.contentType = false;
136+
} else {
137+
// Can't handle file uploads, exit
138+
if ($(form).find(':file').length) {
139+
return;
140+
}
141+
142+
// Fallback to manually serializing the fields
143+
defaults.data = $(form).serializeArray();
144+
}
145+
133146
pjax($.extend({}, defaults, options))
134147

135148
event.preventDefault()

0 commit comments

Comments
 (0)