summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2017-12-10 20:22:33 +0100
committersteckbrief <steckbrief@chefmail.de>2017-12-10 20:22:33 +0100
commit2ec5cbc2aa2fe992d2cccaf6d160950adef521ef (patch)
tree726ff2e5907825469d81ea8af9e900a864ebc4a6 /js
parent6bf09a069577fa9fcefdb0f92da81001465a50e0 (diff)
create story and character improved
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);
+ });
+}