Don't close modal on failure, redirect on success

This commit is contained in:
Phillip Kühne 2019-05-22 03:17:32 +02:00
parent ab1db95d06
commit 1fc2511cbf
3 changed files with 9 additions and 4 deletions

View File

@ -16,7 +16,7 @@ def enqueue():
name = request.json['name'] name = request.json['name']
song_id = request.json['id'] song_id = request.json['id']
database.add_entry(name,song_id) database.add_entry(name,song_id)
return "OK" return Response('{"status":"OK"}', mimetype='text/json')
@app.route("/list") @app.route("/list")
def songlist(): def songlist():

View File

@ -23,4 +23,5 @@
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
<a name="end"></a>
{% endblock %} {% endblock %}

View File

@ -74,7 +74,7 @@
}); });
function enqueue(id,name) { function enqueue(id,name,success_callback) {
var data = { var data = {
"name": name, "name": name,
"id": id "id": id
@ -83,6 +83,7 @@
type: 'POST', type: 'POST',
url: '/api/enqueue', url: '/api/enqueue',
data: JSON.stringify(data), // or JSON.stringify ({name: 'jonas'}), data: JSON.stringify(data), // or JSON.stringify ({name: 'jonas'}),
success: success_callback,
contentType: "application/json", contentType: "application/json",
dataType: 'json' dataType: 'json'
}); });
@ -95,8 +96,11 @@
function submitModal() { function submitModal() {
var name = $("#singerNameInput").val(); var name = $("#singerNameInput").val();
var id = $("#selectedId").attr("value"); var id = $("#selectedId").attr("value");
enqueue(id,name); enqueue(id,name,function(){
$("#enqueueModal").modal('hide'); $("#enqueueModal").modal('hide');
window.location.href = '/#end';
});
} }
</script> </script>