Safe ID getting, question xhttp get refactor

This commit is contained in:
MrFry 2020-01-27 09:46:09 +01:00
parent 7d4dbe4eb6
commit c750261b12

View file

@ -62,7 +62,7 @@
// forcing pages for testing. unless you test, do not set these to true!
// only one of these should be true for testing
const forceTestPage = true
const forceTestPage = false
const forceResultPage = false
const forceDefaultPage = false
const logElementGetting = false
@ -963,6 +963,7 @@
function ShowSaveQuizDialog (sendResult, sentData, newQuestions) {
// FIXME: normal string building with localisation :/
var msg = ''
// TODO: '0 új kérdés'
if (sendResult) {
msg = 'Kérdések elküldve, katt az elküldött adatokért. ' + newQuestions + ' új kérdés'
} else {
@ -1605,10 +1606,10 @@
}
}
function SafeGetElementById (id, todo) {
function SafeGetElementById (id, next) {
let element = document.getElementById(id)
if (element) {
todo(element)
next(element)
} else {
Log(`Unable to safe get element by id: ${id}`)
}
@ -1662,7 +1663,20 @@
url: url,
onload: function (response) {
try {
resolve(JSON.parse(response.responseText))
let res = JSON.parse(response.responseText)
// FIXME: check if res is a valid answer array
// res.json({
// result: r,
// success: true
// })
// ERROR:
// res.json({
// message: `Invalid question :(`,
// result: [],
// recievedData: JSON.stringify(req.query),
// success: false
// })
resolve(res.result)
} catch (e) {
reject(new Error('json parse error'))
}