找不出哪里的问题,收藏电影第一次也会显示 “已经收藏”?,响应正常,第一次ok=1,之后等于0
来源:11-3 .收藏电影2
类嗨宾果啊
2017-10-20
视图 def moviecol_add(): mid = request.args.get("mid", "") uid = request.args.get("uid", "") moviecol = Moviecol.query.filter_by(movie_id=int(mid), user_id=int(uid)).count() if moviecol == 1: data = dict(ok=0) if moviecol == 0: moviecol = Moviecol(movie_id=int(mid), user_id=int(uid)) db.session.add(moviecol) db.session.commit() data = dict(ok=1) import json return json.dumps(data) 模板 <script> $(document).ready(function () { $("#btn-col").click(function () { var mid = {{ movie.id }}; var uid = {{ session['user_id'] }}; $.ajax({ url: "{{ url_for('home.moviecol_add') }}", type: "GET", data: "mid=" + mid + "&uid=" + uid, datatype: "json", success: function (res) { if (res.ok == 1) { $('#show_col_msg').empty(); $("#show_col_msg").append("收藏成功!"); } else { $("#show_col_msg").empty(); $("#show_col_msg").append("已经收藏!"); } } }) }); });
写回答
1回答
-
同学,你好,1代表添加收藏时的响应,0代表已经收藏了,所以不在进行添加收藏操作!
022017-12-22
相似问题