flask前台数据通过ajax传递到后台之点赞与视频播放量
Posted zy_dream
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了flask前台数据通过ajax传递到后台之点赞与视频播放量相关的知识,希望对你有一定的参考价值。
实现功能:
1.点击播放视频,后台视频点击量增加
2.点赞按钮,点击为红色,后台视频赞数增加;再次点赞,按钮变为灰色,后台视频赞数不增加
前台点赞按钮:
<a href="#" id="zan- v.id " name="iconfont zan">
<i class="iconfont zan"></i>
</a>
点赞 js:
$("#zan- v.id ").click(function ()
if (this.name == "iconfont zan")
this.innerhtml = "<i class='iconfont unzan'></i>";
this.name = "iconfont unzan";
var likes = v.like_num +1;
var url = " url_for('grade.make_likes', id=project.id) ";
var data_dic =
'like': likes,
'video': ' v.id '
;
$.ajax(
type: 'POST',
url: url,
data: JSON.stringify(data_dic),
contentType: 'application/json; charset=UTF-8',
dataType: 'json',
success: function (data)
window.history.back();
);
else
this.innerHTML = "<i class='iconfont zan'></i>";
this.name = "iconfont zan";
var likess = v.like_num ;
var urls = " url_for('grade.make_likes', id=project.id) ";
var data_dics =
'like': likess,
'video': ' v.id '
;
$.ajax(
type: 'POST',
url: urls,
data: JSON.stringify(data_dics),
contentType: 'application/json; charset=UTF-8',
dataType: 'json',
success: function (data)
window.history.back();
);
);
var myvideo1 = document.getElementById('myvideo- v.id ');
myvideo1.setAttribute("src", ' v.path ');
myvideo1.addEventListener('play', function ()
var views = v.view_num +1;
var url = " url_for('grade.make_views', id=project.id) ";
var data_dic =
'view': views,
'video': ' v.id '
;
$.ajax(
type: 'POST',
url: url,
data: JSON.stringify(data_dic),
contentType: 'application/json; charset=UTF-8',
dataType: 'json',
success: function (data)
);
);
以上是关于flask前台数据通过ajax传递到后台之点赞与视频播放量的主要内容,如果未能解决你的问题,请参考以下文章
关于后台数据库正常存储中文通过Ajax方式传递到前台变成问号的处理