I am trying to build an application for educational/entertainment reasons. I use python/flask on the backend for rendering the pages and some plain js/jquery on the frontend to manipulated the document whenever is necessary. So far so good but i am in the point that i want to add images upload functionality.
The basic idea is that user tries to upload images, javascript requests backend, backend make the validation and if everything is ok proceeds with the uploading. Meanwhile I use socket.io on the frontend and flask_socketio on the backend in order to show the user possible errors, finished upload done messages, e.t.c.
The problem is that whenever i use jQuery to append an element this element will be appended only after everything else in javascript block has been executed.
socket.on('error', function(msg) {
alert('error triggered');
$('#test').append(`
<div class="alert alert-warning mt-2" id="file_type_error" role="alert"> this type of file is not supported </div>
`);
alert('if i see this before error this is the problem');
});
So when i run this code what is happening is this: First page alerts me 'errors triggered) then alerts me 'if i see this before error this is the problem' and only afterwards it's add the error on the page.
This is huge problem for me because i have other js blocks if they append the element after everything else is executed in the block, it's totally affect what i aim to do.
I have very little experience in frontend development so any suggestion will be welcome.