I tried to send a request to my Flask App via JavaScript. My JS code is the following:
$.ajax({
url: 'localhost:5000/api/login',
method: 'POST',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "lel",
success: function (response) {
alert("Erfolgreich " + response )
},
error: function (jqXHR, exception) {
alert("code: " + jqXHR.status + " " + exception.toString());
}
});
This is my Flask function for /api/login
@app.route("/api/login", methods=['POST'])
def api_login():
return "it works"
My JavaScript output over the alert is: code: 200 parsererror The Flask console output is:
XX.XXX.XX.XX - - [28/Apr/2020 15:48:20] "[37mOPTIONS /api/login HTTP/1.1[0m" 200 -
XX.XXX.XX.XX - - [28/Apr/2020 15:48:21] "[37mPOST /api/login HTTP/1.1[0m" 200 -
Why is this happening and how can I fix it?