I just want to transfer data from my javascript file to python. I tried to do this via ajax request, but I get a console error:
POST http://127.0.0.1:5000/ net::ERR_CONNECTION_REFUSED
here is a part of my code responsible for transferring data from js:
function getAccountInfo () {
const number = 5
const message = 'some text'
const dict_values = {number, message}
const s = JSON.stringify(dict_values);
console.log(s)
$.ajax({
url:"http://127.0.0.1:5000/test",
type:"POST",
contentType:"application/json",
data: JSON.stringify(s)
});
}
that is my python code:
from flask import Flask, render_template, request, redirect, session
import json
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/test', methods=['POST'])
def test():
output = request.get_json()
print(output)
print(type(output))
result = json.loads(output)
print(result)
print(type(result))
return result
if __name__ == '__main__':
app.run(debug=True)
the flask application by default is launched on http://127.0.0.1:5000/
:
so i cant imagine why i have this problem