uv: Add error handler to uv autofill

This commit is contained in:
tleb
2019-10-21 10:34:46 +02:00
parent 4094394cef
commit 53a7633700
2 changed files with 127 additions and 113 deletions

View File

@ -52,24 +52,32 @@
year--
}
const url = "{{ url('api:uv_endpoint') }}?year=" + year + "&code=" + codeInput.value
$.getJSON(url, function(data, _, xhr) {
if (xhr.status != 200) {
alert("{% trans %}Unknown UV code{% endtrans %}")
return
}
for (let key in data) {
if (data.hasOwnProperty(key)) {
const el = document.querySelector('[name="' + key + '"]')
if (el.tagName == 'TEXTAREA') {
el.parentNode.querySelector('.CodeMirror').CodeMirror.setValue(data[key])
} else {
el.value = data[key]
}
$.ajax({
dataType: "json",
url: url,
success: function(data, _, xhr) {
if (xhr.status != 200) {
alert("{% trans %}Unknown UV code{% endtrans %}")
return
}
}
for (let key in data) {
if (data.hasOwnProperty(key)) {
const el = document.querySelector('[name="' + key + '"]')
if (el.tagName == 'TEXTAREA') {
el.parentNode.querySelector('.CodeMirror').CodeMirror.setValue(data[key])
} else {
el.value = data[key]
}
alert('{% trans %}Successful autocomplete{% endtrans %}')
}
}
alert('{% trans %}Successful autocomplete{% endtrans %}')
},
error: function(_, _, statusMessage) {
alert('{% trans %}An error occured: {% endtrans %}' + statusMessage)
},
})
})
})