From f9c4bd9b5af8c3285842515b5659ef03f21a66d2 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 3 Jul 2018 21:45:17 +0200 Subject: Ajax instead of form for avatar post. --- resources/assets/js/app.js | 1 + resources/assets/js/profile.js | 26 ++++++++++++++++++++++++++ resources/assets/js/setup.js | 5 +++++ resources/assets/sass/app.scss | 4 ++++ 4 files changed, 36 insertions(+) create mode 100644 resources/assets/js/setup.js (limited to 'resources/assets') diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 16d3a12..f50f805 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -7,5 +7,6 @@ window.openpgp = require('openpgp'); window.Vue = require('vue'); require('./bootstrap'); +require('./setup'); require('./profile'); require('./chat'); diff --git a/resources/assets/js/profile.js b/resources/assets/js/profile.js index bce94da..d834542 100644 --- a/resources/assets/js/profile.js +++ b/resources/assets/js/profile.js @@ -10,4 +10,30 @@ $("#avatarFile").on("change", () => { if (file) { reader.readAsDataURL(file); } +}); + +$("#avatarForm").submit(function (e) { + var url = "/avatar"; + var data = new FormData(); + $.each(jQuery('#avatarFile')[0].files, (i, file) => { + data.append('avatar', file); + }); + + e.preventDefault(); + $.ajax({ + url: url, + data: data, + cache: false, + contentType: false, + processData: false, + method: 'POST', + type: 'POST', + success: (data) => { + $("#avatarUploadSucceededAlert").show(); + $("#avatarUploadSucceededMessage").text(data.success); + }, + error: () => { + $("#avatarUploadFailedAlert").show(); + } + }); }); \ No newline at end of file diff --git a/resources/assets/js/setup.js b/resources/assets/js/setup.js new file mode 100644 index 0000000..880bf91 --- /dev/null +++ b/resources/assets/js/setup.js @@ -0,0 +1,5 @@ +$.ajaxSetup({ + headers: { + 'X-CSRF-Token': $('input[name="_token"]').val() + } +}); \ No newline at end of file diff --git a/resources/assets/sass/app.scss b/resources/assets/sass/app.scss index ce64b3f..bd5e1a5 100644 --- a/resources/assets/sass/app.scss +++ b/resources/assets/sass/app.scss @@ -13,4 +13,8 @@ .navbar-laravel { background-color: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04); +} + +.alert { + display: none; } \ No newline at end of file -- cgit v1.2.3