Skip to content

Commit 08a785d

Browse files
committed
Merge pull request #353 from bfrohs/fileFields
Add support for file input fields
2 parents 5089a18 + c7b4457 commit 08a785d

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
@@ -131,11 +131,24 @@ function handleSubmit(event, container, options) {
131131
var defaults = {
132132
type: form.method.toUpperCase(),
133133
url: form.action,
134-
data: $(form).serializeArray(),
135134
container: $(form).attr('data-pjax'),
136135
target: form
137136
}
138137

138+
if (defaults.type !== 'GET' && window.FormData !== undefined) {
139+
defaults.data = new FormData(form);
140+
defaults.processData = false;
141+
defaults.contentType = false;
142+
} else {
143+
// Can't handle file uploads, exit
144+
if ($(form).find(':file').length) {
145+
return;
146+
}
147+
148+
// Fallback to manually serializing the fields
149+
defaults.data = $(form).serializeArray();
150+
}
151+
139152
pjax($.extend({}, defaults, options))
140153

141154
event.preventDefault()

0 commit comments

Comments
 (0)