我试图创建一个函数,如果用户没有足够的积分,则无法扣减积分。我正在使用MVC来做到这一点。 它将提示用户他们的分数不足以从问题中得到答案。 回答
答案 0 :(得分:0)
您可以通过Jquery进行Ajax Get函数来获取人物的分数
然后您可以检查一个人的点数是否大于10 .. 否则显示警报..
示例:
if (confirm("Are you sure you want an answer? It will deduct 10 points.")) {
$.ajax({
type: "post",
url: "@Url.Content("~/")API/PointsTransaction/PointsTransactAnswer",
contentType: "application/json; charset=utf-8",
success: function(obj) {
// let make * Ppoints * is person points that we have gitten from Ajax
if (Ppoints > 10 ) {
// show the answer
}else {
alert("oops, you don't have enough points to show this answer")
}
}
});
}
还有..使用按钮时,您可以使用Jquery进行功能。
$(document).ready(function() {
$('#answer').click(function() {
// what to do if the button clicked
})
})
希望我能帮助您! 和我的英语不好对不起。
答案 1 :(得分:0)
hi @ rod在您的ajax调用中,您可以获得用户的积分,并且在成功时,如果积分大于10,您可以做其他事情
< a href = "#" class = "btn" id = "answer" onclick = "return Confirm()" > Answer < /a>
< script type = "text/javascript" >
"use strict";
function Confirm() {
var text;
if (confirm("Are you sure you want an answer? It will deduct 10 points.")) {
$.ajax({
type: "post",
url: "@Url.Content("~/")API/PointsTransaction / PointsTransactAnswer",
contentType: "application/json; charset=utf-8",
success: function(obj) {
if (obj.points > 10){
// do whatever you want if points of user is grater than 10 .
} else{
// if points of user is less than 10 show message.
alert('Oops. points is less than 10 . ');
}
}
});
text = "";
return true;
} else {
return false;
}
}