我正在开发一个烧瓶应用程序,我将这个ajax请求发送给' / repl'端点
$.ajax({
type: "GET",
url : "/repl?code=",
data: "print \"hello\"",
contentType: 'application/json;charset=UTF-8',
success: function(result){
alert(result.output);
}
});
和我的控制器的代码,即view.py是
@app.route('/repl', methods=['GET'])
@app.route('/repl/', methods=['GET'])
def execute():
code = request.args.get("code", None)
print code
# execute python code in sandbox
out, err = exec_sandbox(str(code))
return jsonify(success=1, output=out, error=err)
但它不起作用。代码变量始终接收无值。请帮忙
运行应用后,此请求会建立
127.0.0.1 - - [28/Mar/2014 03:59:59] "GET /repl/?code=&print%20%22hello%22 HTTP/1.1" 200
答案 0 :(得分:2)
将ajax代码更改为:
$.ajax({
type: "GET",
url : "/repl",
data: {url : "print \"hello\""},
contentType: 'application/json;charset=UTF-8',
success: function(result){
alert(result.output);
}
});