Only use ajax for file upload. Prepare for handling of duplicate error.

This commit is contained in:
Bart Kamphorst
2018-11-02 14:38:12 +01:00
parent eade94dcfd
commit 6857995442
3 changed files with 26 additions and 10 deletions
@@ -228,8 +228,8 @@
}
window.ace_editor.insert(text);
},
error: function(r, textStatus) {
alert('Error uploading file: ' + textStatus);
error: function(r, textStatus, errorThrown) {
alert('Error uploading file: ' + textStatus + ' ' + errorThrown);
$editorBody.removeClass('uploading');
}
});
@@ -158,6 +158,7 @@ $(document).ready(function() {
}
};
// ua detection
if ($.browser.mozilla) {
$('body').addClass('ff');
@@ -187,7 +188,26 @@ $(document).ready(function() {
}
],
OK: function( res ) {
$('#upload').submit();
var formData = new FormData($('#upload').get(0));
var endpoint = $('#upload').attr("action");
$.ajax({
url: endpoint,
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data) {
// File successfully uploaded
},
error: function(data, textStatus, errorThrown) {
if (data.status == 409) {
alert('This file already exists.');
} else {
alert('Error uploading file: ' + textStatus + ' ' + errorThrown);
}
}
});
}
});
});