0
我正在提交一個字符串,並且想要從服務器上取回它。問題似乎是Flask的Request模塊沒有獲取URL參數 - 即我得到「HELLO」而不是字符串變量。Flask沒有從AJAX調用中接收URL參數
另外,console.log(status)是未定義的,我不確定它是否相關。
下面是HTML ...
<html>
<script type="text/javascript" src= "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
<form>
<input id = "entered_string" name = "string">
<input type = "button" value = "submit" id = "submit_button">
</form>
<div id = "result">?</div>
<script>
$("#submit_button").bind("click", function(data, status){
var string = $("#entered_string").val()
console.log(string)
console.log(data)
console.log(status)
$.get('/upper_case', function(string){
console.log(string)
$("#result").text(string.result)
})
})
</script>
</html>
和服務器端的代碼...
@app.route('/', methods = ['GET', 'POST'])
def case_converter():
return render_template("new.html")
@app.route('/upper_case')
def upper():
print request.args
string = request.args.get('string', "hello", type=str)
print string
return jsonify(result = string)
謝謝,不知道爲什麼,我錯過了這一點: - / –