Skip to content
Advertisement

How to get the position data from the joystick to the flask server?

I would like to get the position data from the js joystick o use it at the flask server. I tried using ajax:

python:

@app.route(‘/test’, methods=[‘GET’, ‘POST’]) def test_ajax():

JavaScript

JavaScript

Every time the position of the joystick changed I would like to send the position data to flask

Advertisement

Answer

You can simply use the callback function to send the joystick data. In this example I use fetch to transfer the data via AJAX.

JavaScript
JavaScript

If you accept the legitimate suggestion of using websockets, I would recommend Flask-SocketIO.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement