目前可以透過javascript 向python request,但不知道python如何給予javascript那邊response 或是javascript那邊該如何接收。
javascript call api:
let url= 'http://127.0.0.1:8000/fix?item_id='+item_id;
let xhr = new XMLHttpRequest();
xhr.open('GET',url,true);
xhr.send();
xhr.onload = function(data) {
console.log(xhr.responseText);
};
python response:
app = Flask(__name__)
@app.route('/fix', methods=['GET'])
def fixed():
data = request.args.get('item_id')
resp = Response(response='about page',status=200,content_type='text/html;charset=utf-8')
return resp
if __name__ == '__main__':
app.run(
host="127.0.0.1",
port=int("8000"))