+ now correctly working error messages

Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
Johannes Theiner 2019-06-05 17:33:55 +02:00
parent 4068239070
commit e0bfd8826f
2 changed files with 17 additions and 20 deletions

View File

@ -17,27 +17,23 @@ form.onsubmit = function (event) {
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.onloadstart = function(e) { xhr.onloadstart = function (e) {
loading.removeClass("hide"); loading.removeClass("hide");
$('.sidenav').sidenav('close'); $('.sidenav').sidenav('close');
loading.modal('open'); loading.modal('open');
}; };
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
if(xhr.responseText != null) {
loading.modal('close');
console.log(xhr.responseText);
$('#error-message').text(xhr.responseText);
error.modal('open');
}
}
}
xhr.onloadend = function (e) { xhr.onloadend = function (e) {
clearSelected(); clearSelected();
if (/[a-z]/.test(xhr.responseText)) {
console.log(xhr.responseText);
loading.modal('close');
$('#error-message').text(xhr.responseText);
error.modal('open');
}
updateDatasets(); updateDatasets();
form.reset(); form.reset();
}; };
xhr.open('POST', form.getAttribute('action'), true); xhr.open('POST', form.getAttribute('action'), true);

View File

@ -144,15 +144,16 @@
<div class="modal-footer"> <div class="modal-footer">
</div> </div>
</div>
<div id="error" class="modal"> <div id="error" class="modal">
<div class="modal-content"> <div class="modal-content">
<h4>Es ist ein Fehler aufgetreten</h4> <i class="material-icons">error_outline</i>
<p id="error-message">A bunch of text</p> <h2 class="center">Fehler</h2>
</div> <h4 id="error-message" class="center">Hallo Welt, das sollte nie zu sehen sein.</h4>
<div class="modal-footer"> </div>
<a href="#!" class="modal-close waves-effect waves-green btn-flat">Ok</a> <div class="modal-footer">
</div> <a href="#!" class="modal-close waves-effect waves-green btn-flat">Ok</a>
</div> </div>
</div> </div>