我正在尝试处理下面的代码,从后端Python代码中获得成功和失败Ajax响应
后端代码只返回成功ajax响应,只有前端成功ajax代码被触发,而不是失败代码,即使后端代码将失败响应返回给前端
我试图通过输入错误的OTP从后端代码发送否定的失败响应,但是仍然触发了前端成功方法,该方法会发出带有成功消息的警报
function myFunction() {
$.ajax({
url: '/ValidateOTP',
type: 'POST',
data:JSON.stringify( $('#OTP').val()),
contentType: 'application/json;charset=UTF-8',
success: function(response){
alert("Success")
},
error: function(response){
alert("Failure")
}
});
};
@app.route('/ValidateOTP', methods=['GET','POST'])
def ValidateOTP():
OTP = request.get_json()
otpinstant=session['OTPINSTA']
if otpinstant==OTP:
Session = sessionmaker(bind=engine)
s = Session()
query = s.query(ElectricMan).filter_by(email_id=email).first()
result=query.first_name
if result:
session['logged_in'] = True
return home()
else:
return home()
else:
return home()
目前没有回答
相关问题 更多 >
编程相关推荐