javascript - How to post an HTTP request from a JS script running on a website to my local server (localhost) -
i have following flask (python) server:
from flask import flask, render_template, request, redirect, response,jsonify import random, json app = flask(__name__) @app.route('/') def output(): return redirect("this temporary implementation.") @app.route('/model',methods = ['post']) def ask_model(): data = request.get_json(force=true) print("data recieved: "+str(data)) return jsonify({'vlaue': "some response"}) if __name__ == '__main__': # run! #the "ip:port" server listens "localhost:5000" app.run()
i have js script running on website called slither.io (source: https://github.com/ermiyaeskandary/slither.io-bot)
i want create learning bot , in order need send requests between js script , server, don't how it.
for example, added following lines script:
console.log("pre-post"); $.post('http://localhost:5000/model',json.stringify(canvasutil.maptomouse(window.goalcoordinates)), function(){ console.log("entered model function."); },'json'); console.log("post-post");
when @ console log "pre-post" printed, , server doesn't receives request.
why doesn't requests local server? how fix server requests , respond them?
as cbore said, have handle coors correctly, have use ip addres of localhost server, should have static ip or when localhost ip address changes request doesn't reach server anymore
Comments
Post a Comment