summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/stories.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/js/stories.js b/js/stories.js
new file mode 100644
index 0000000..535bb85
--- /dev/null
+++ b/js/stories.js
@@ -0,0 +1,42 @@
+function createNewCharacter() {
+ var formName = 'create-char-form';
+ var url = 'createCharacter.php';
+ var modalName = 'newCharModal';
+ create(formName, url, modalName);
+}
+
+function createNewStory() {
+ var formName = 'create-story-form';
+ var url = 'createStory.php';
+ var modalName = 'newStoryModal';
+ create(formName, url, modalName);
+}
+
+function create(formName, url, modalName) {
+ var form = $('#' + formName)[0];
+ var data = new FormData(form);
+ //var file = $('#story-logo').prop('files')[0];
+ //data.append('file', file);
+ jQuery.ajax({
+ url: url,
+ data: data,
+ cache: false,
+ contentType: false,
+ processData: false,
+ method: 'POST'
+ }).done(function(data, textStatus) {
+ console.log("Success!");
+ console.log(data);
+ console.log(textStatus);
+ $('#' + modalName).modal('hide');
+ }).fail(function(jqXHR, textStatus) {
+ if (409 == jqXHR.status) {
+ var errorElement = $('<div id="error">').text('Ein Charakter mit diesem Namen existiert bereits');
+ $(form).append(errorElement);
+ } else if (500 == jqXHR.status) {
+ }
+ console.log("An error occurred, the files couldn't be sent!");
+ console.log(jqXHR);
+ console.log(textStatus);
+ });
+}