我对 Web 开发比较陌生。基本上,我正在烧瓶中创建一个应用程序。我现在要做的是测试一个 AJAX 函数,看看它是否工作。AJAX 函数从 html 读取无线电输入。我想在 html 中显示 AJAX 调用,以查看我的代码是否正常工作。
这是我的 html 代码(index.html):
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions1" id="option1" value="option1">
<label class="form-check-label" >Yes</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions1" id="option2" value="option2">
<label class="form-check-label">No</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions1" id="option3" value="option3">
<label class="form-check-label">Dunno</label>
</div>
这是我的 AJAX 函数:
$(function(){
$('#btnSubmit').click(function(){
var radioValue1 =
$("input[name=inlineRadioOptions1]:checked").val();
$.ajax({
url: '/process',
data: {value1: radioValue1},
type: 'POST',
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
});
});
});
这是我在python中的代码:
from flask import Flask, render_template, request, jsonify
# App config.
DEBUG = True
app = Flask(__name__)
app.config.from_object(__name__)
app.config['SECRET_KEY'] = '7d441f277y7ttt8t88tb'
@app.route("/")
def index():
return render_template('index.html')
@app.route('/process', methods = ['POST'])
def process():
v1 = request.form['value1']
return jsonify({'v1': v1})
if __name__ == "__main__":
app.run(debug = True)
现在我想使用 div 标签在 index.html 中显示值 v1。我怎样才能做到这一点?
蓝山帝景
慕村9548890
相关分类