From 101fa47c58b80841556532728d0c2417e5c19557 Mon Sep 17 00:00:00 2001 From: Tiberiu Chibici Date: Sat, 3 Nov 2018 14:41:08 +0200 Subject: [PATCH] Handle enctype="multipart/form-data" properly in modal ajax call. --- .../templates/YtManagerApp/js/common.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/YtManagerApp/templates/YtManagerApp/js/common.js b/app/YtManagerApp/templates/YtManagerApp/js/common.js index d0fe045..f737178 100644 --- a/app/YtManagerApp/templates/YtManagerApp/js/common.js +++ b/app/YtManagerApp/templates/YtManagerApp/js/common.js @@ -53,7 +53,21 @@ class AjaxModal _submit(e) { let pThis = this; let url = this.form.attr('action'); - $.post(url, this.form.serialize()) + let ajax_settings = { + url: url, + }; + + if (this.form.attr('enctype') === 'multipart/form-data') { + ajax_settings.data = new FormData(this.form[0]); + ajax_settings.contentType = false; + ajax_settings.processData = false; + ajax_settings.cache = false; + } + else { + ajax_settings.data = this.form.serialize(); + } + + $.post(ajax_settings) .done(function(result) { pThis._submitDone(result); })