File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,19 @@ $.fn.ajaxSubmit = function(options) {
210
210
this . trigger ( 'form-submit-notify' , [ this , options ] ) ;
211
211
return this ;
212
212
213
+ // This is a utility function to fix deep serialization issues when doing file uploads
214
+ // eg params show up as "[object Object]" rather than what it should be
215
+ function formDeepSerialize ( extraData ) {
216
+ var serialized = $ . param ( extraData ) . split ( '&' ) ;
217
+ var result = { } ;
218
+ var n ;
219
+ for ( var i = 0 , l = serialized . length ; i < l ; i ++ ) {
220
+ n = serialized [ i ] . split ( '=' )
221
+ result [ decodeURIComponent ( n [ 0 ] ) ] = decodeURIComponent ( n [ 1 ] )
222
+ }
223
+ return result ;
224
+ }
225
+
213
226
// XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
214
227
function fileUploadXhr ( a ) {
215
228
var formdata = new FormData ( ) ;
@@ -219,9 +232,10 @@ $.fn.ajaxSubmit = function(options) {
219
232
}
220
233
221
234
if ( options . extraData ) {
222
- for ( var p in options . extraData )
223
- if ( options . extraData . hasOwnProperty ( p ) )
224
- formdata . append ( p , options . extraData [ p ] ) ;
235
+ var serializedData = formDeepSerialize ( options . extraData ) ;
236
+ for ( var p in serializedData )
237
+ if ( serializedData . hasOwnProperty ( p ) )
238
+ formdata . append ( p , serializedData [ p ] ) ;
225
239
}
226
240
227
241
options . data = null ;
You can’t perform that action at this time.
0 commit comments