2014-03-27 152 views
0

我在燒瓶中的應用程序工作,我送這個Ajax請求「/ REPL」端點Ajax請求不工作

 $.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) 

但它不工作。代碼變量總是接收None值。請幫助

運行的應用程序後,這一要求建立起

127.0.0.1 - - [28/Mar/2014 03:59:59] "GET /repl/?code=&print%20%22hello%22 HTTP/1.1" 200 

回答

1

變化AJAX代碼:

$.ajax({ 
    type: "GET", 
    url : "/repl", 
    data: {url : "print \"hello\""}, 
    contentType: 'application/json;charset=UTF-8', 
    success: function(result){ 
     alert(result.output); 
    } 
    }); 
+0

是它的工作,但我已經在數據傳入的參數爲:{代碼:「打印\ 「你好」」} – Rahul