老师,我在跟着7-5视频做编辑功能时,写好edit.js后刷新网页,点击保存没反应
来源:7-5 编辑和修改登录人信息
blood_kyo
2019-05-10
#这是edit.js文件代码,我已经在edit.html中引入json了
;
var user_edit_ops ={
init:function (){
this.eventBind();
},
eventBind:function(){
$(".user_edit_wrap .save").click(function(){
vat btn_target = $(this);
if(btn_target.hasClass(“disabled”)){
common_ops.alert(“正在处理!请不要重复提交~~”);
return;
}
var nickname_target = $(".user_edit_wrap input [name=nickname]");
var nickname = nickname_target.val();
var email_target = $(".user_edit_wrap input [name=email]");
var email = email_target.val();
if( !nickname || nickname.length <2){
common_ops.tip("请输入符合规范的姓名~~", nickname_target);
return false;
}
if( !email || email.length <2){
common_ops.tip("请输入符合规范的邮箱~~", nickname_target);
return false;
}
btn_target.addClass("disabled");
var data = {
nickname: nickname,
email:email
};
$.ajax({
url:common_ops.buildUrl("/user/edit"),
type:'POST',
data:data,
dataType:'json',
success:function(res){
btn_target.removeClass("disabled");
var callback = null;
if(res.code == 200){
callback = function() {
window.location.href = window.location.href;
}
}
common_ops.alert(res.msg, callback);
}
});
});
}
};
$(document).ready( function(){
user_edit_ops.init();
});
点击保存,并没有想视频中的提示那样 有红色的提示:请输入规范的姓名。修改之后并保存,在右上角的头像那看到的姓名和邮箱还是之前的,这是怎么回事?
2回答
-
blood_kyo
提问者
2019-05-10
#这是User.py中的/edit路径的相关代码
@route_user.route( "/edit", methods = ["GET", "POST"] )
def edit():
if request.method == "GET":
return ops_render( "user/edit.html" )
resp = {'code':200, 'msg':'操作成功~', 'data':{}}
req = request.values
nickname = req['nickname'] if 'nickname' in req else ''
email = req['email'] if 'email' in req else ''
if nickname is None or len(nickname) < 1:
resp['code'] = -1
resp['msg'] = "请输入规范的姓名~~"
return jsonify(resp)
if email is None or len(email) < 1:
resp['code'] = -1
resp['msg'] = "请输入规范的邮箱~~"
return jsonify(resp)
user_info = g.current_user
user_info.nickname = nickname
user_info.email = email
db.session.add(user_info)
db.session.commit()
return jsonify(resp)00 -
blood_kyo
提问者
2019-05-10
这是网页调试器的情况
032019-05-10
相似问题