所以我的应用程序有一个编辑页面功能,提交按钮似乎不起作用。我不知道自己做错了什么。我确保所有变量都相互排列。一旦我点击提交,它什么都不做。它没有通知我它是成功的,也没有给我一个错误信息。当我检查数据库时,信息根本没有更新。
这是我的HTML:
<div class="col-xs-4" >
<input type="text" id="e_firstc" name="e_firstc" class="form-control" placeholder="First Name"><br>
<input type="text" id="e_lastc" name="e_lastc" class="form-control" placeholder="Last Name"><br>
<input type="date" id="e_birthdatec" name="e_birthdatec" class="form-control" placeholder="Birthdate"><br>
<input type="number" id="e_agec" name="e_agec" class="form-control" placeholder="Age"><br>
<input type="text" id="e_disorderc" name="e_disorderc" class="form-control" placeholder="Diagnosis"><br>
<br>
<button type="submit" class="btn btn-default" onclick="edit_child();">Submit</button>
<br>
<br>
<script src="jQuery-2.1.4.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="app.js"></script>
</div>
app.js:
function edit_child() {
var first_name = $('#first_name').text();
$.ajax(
{
url: 'http://127.0.0.1:5000/childinfo_edit/'+first_name+'/',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
'e_firstc': $("#e_firstc").val(),
'e_lastc': $("#e_lastc").val(),
'e_birthdatec': $("#e_birthdatec").val(),
'e_agec': $("#e_agec").val(),
'e_disorderc': $("#e_disorderc").val(),
}),
type: "POST",
dataType: "json",
error: function (e) {
},
success: function (resp) {
if (resp.status == 'ok') {
alert("successfully updated")
}
else {
alert("ERROR")
}
}
});
}
app.py:
@app.route('/edit_childinfo/<string:first_name>/', methods=['POST', 'GET'])
def edit_child(first_name):
params = request.get_json()
e_firstc = params["e_firstc"]
e_lastc = params["e_lastc"]
e_birthdatec = params["e_birthdatec"]
e_agec = params["e_agec"]
e_diagnosisc = params["e_diagnosisc"]
res = spcall("edit_child",(first_name, e_firstc, e_lastc,e_birthdatec, e_agec, e_diagnosisc), True)
recs = []
for r in res:
recs.append({"e_firstc": r[0], "e_lastc": r[1], "e_birthdatec": r[2], "e_agec": r[3], "e_diagnosisc": r[4]})
return jsonify({'status': 'ok', 'entries': recs, 'count': len(recs)})