Save Map button not working
DylanBulmer opened this issue · comments
Dylan Bulmer commented
Currently the button is visible, and runs a JavaScript function when clicked.
Bug in function:
When running the function, the canvas data URL is captured and sent in a form using AJAX. The AJAX does send the form to the server, but the server throws a 400 error saying it didn't get anything.
Server Code:
@app.route('/game/<id>', methods=["POST", "GET"])
def serveGameUpdate(id):
if request.method == "POST":
print('Getting Data')
data = request.form['map']
FileStorage(stream=data).save(SERVER+id, id+'.png')
return 'ok'
Client Code:
save: function() {
let img = game.map.canvas.toDataURL("image/png")
let form = new FormData;
form.append('map', img);
form.append('id', data.id);
let ajax = new XMLHttpRequest();
ajax.open("POST",window.location.href);
ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajax.send(form);
}
Dylan Bulmer commented
Put on standby for the time being. I plan on making this feature use a web socket instead.