summaryrefslogtreecommitdiff
path: root/assets/js/core
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-02-12 13:34:56 -0500
committerFrederic Guillot <fred@kanboard.net>2017-02-12 13:34:56 -0500
commit991f7426e8ec2a566ad82043b22ce844a5a1cfa1 (patch)
treea0ff32313ad511ebdd9ea71180c86aa5b0002204 /assets/js/core
parenta172e3ad8d25e9b77616107ce8a622175ab0d698 (diff)
Improve error reporting when file upload is not configured properly
Diffstat (limited to 'assets/js/core')
-rw-r--r--assets/js/core/http.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/assets/js/core/http.js b/assets/js/core/http.js
index 745435cc..ad321cf1 100644
--- a/assets/js/core/http.js
+++ b/assets/js/core/http.js
@@ -83,14 +83,25 @@ KB.http.postForm = function (url, formElement) {
return (new KB.http.request('POST', url, {}, formData)).execute();
};
-KB.http.uploadFile = function (url, file, onProgress, onComplete, onError) {
+KB.http.uploadFile = function (url, file, onProgress, onComplete, onError, onServerError) {
var fd = new FormData();
fd.append('files[]', file);
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', onProgress);
- xhr.upload.addEventListener('load', onComplete);
xhr.upload.addEventListener('error', onError);
xhr.open('POST', url, true);
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
+
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState === XMLHttpRequest.DONE) {
+ if (xhr.status === 200) {
+ onComplete();
+ } else if (typeof onServerError !== 'undefined') {
+ onServerError(JSON.parse(xhr.responseText));
+ }
+ }
+ };
+
xhr.send(fd);
};