I have a JS click function and want to send some data to a python file to process.
In the JS File:
$(#button).click(function(){
// did some data collection
$.ajax{
type: "POST",
url: "/dummy",
data: {num: 123},
success: function(result){
alert(result);
}
error: function(xhr, status, error){
alert(xhr.status)
}
}
})
And in the python file after importing:
app = Flask(__name__)
@app.route('/dummy', methods=['GET', 'POST'])
def dummy(){
return 1
}
if __name__ == '__main__':
app.run(debug=True)
I keep getting the alert 0 when clicking the button.
Why the ajax request does not pass through and has a 0 status?