【发布时间】:2014-11-06 02:09:50
【问题描述】:
我正在编写一些代码,主要是使用 mysql、jquery 和 flask 来制作用户名和密码框。目前我的 mysql 数据库 100% 正常工作,但 Flask 不会将值返回到 JQuery,所以我无法更新我的 html 中的 div。编辑:使用 console.log 有一个错误,只是“”
这是我目前在 Flask 中遇到问题的方法
@app.route("/authentication/")
def validation():
username = {"value": request.args.get('echoValue')}
password = {"value": request.args.get('echoValue2')}
cursor = mysql.connect().cursor()
cursor.execute("SELECT * from _accounts where Username='" + str(username['value']) + "' and Password='" + str(password['value']) + "'")
data = cursor.fetchone()
if data is None:
return "Username or Password is wrong"
else:
return "Logged in successfully"
这里是试图输出对 div 结果的响应的 JQuery:
<script type=text/javascript>
$(function() {
$("#sign-in").click(function() {
$.ajax({
type: "GET",
url: "/authentication/",
contentType: "application/xml; charset=utf-8",
data: { echoValue: $('input[name="username"]').val(), echoValue2: $('input[name="password"]').val() },
success: function(data) {
alert("working")
alert(data)
$('#results').text(data.value);
}
});
});
});
</script>
【问题讨论】:
标签: jquery python html mysql ajax