【发布时间】:2020-02-23 16:20:51
【问题描述】:
我想将一个字符串从我的 Flask 应用程序发送到一个 .js 文件(不是 HTML 上的脚本)。我知道我需要使用 Ajax 'GET' 类型,但我不确定如何在 .js 文件和 console.log 数据中接收它。
@app.route('/',methods =['GET','POST'])
def index():
req = json.dumps(request.get_json())
if request.method == 'POST':
result = getString(req) #Function outputs a string
print('Received')
return jsonify(result)
else:
print('Not Received')
return render_template('index.html')
if __name__ == '__main__':
app.run()
.js 文件(需要帮助):
$.ajax({
url: "/",
type: 'GET',
data: ???, #What should i put here
success: function(data) {
console.log(data);
}
});
【问题讨论】:
标签: javascript python json ajax flask