Commit 53a76337 authored by tleb's avatar tleb

uv: Add error handler to uv autofill

parent 4094394c
Pipeline #2114 passed with stage
in 32 minutes and 56 seconds
This diff is collapsed.
...@@ -52,24 +52,32 @@ ...@@ -52,24 +52,32 @@
year-- year--
} }
const url = "{{ url('api:uv_endpoint') }}?year=" + year + "&code=" + codeInput.value 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)
},
}) })
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment