【问题标题】:Alert users if user do not have enough points如果用户没有足够的积分,则提醒用户
【发布时间】:2019-01-04 00:45:15
【问题描述】:

我试图创建一个功能,如果用户没有足够的积分,则无法扣除积分。我正在使用 MVC 来做到这一点。 它会提示用户他们没有足够的分数来从问题中得到答案。 回答

【问题讨论】:

  • 让您的操作方法执行相关代码并生成响应(其中包含一条消息),您可以使用成功事件处理程序中的响应向用户显示该消息。
  • @Shyju 你能告诉我怎么做吗?谢谢
  • 您想知道的具体内容。你现在的问题太宽泛了。指定您在工作中遇到困难的具体事情。
  • 当用户没有足够的积分购买答案时提醒用户
  • 我想写一个答案来帮助你。但是我怎么知道用户什么时候没有足够的积分呢?

标签: javascript jquery html ajax asp.net-mvc


【解决方案1】:

您可以从 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
  })
  })

希望能帮到你! 对不起我的英语不好。

【讨论】:

    【解决方案2】:

    您好 @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;
                     }
    
    
                     }
    

    【讨论】:

      猜你喜欢
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-24
      • 2015-09-30
      • 2019-04-28
      相关资源
      最近更新 更多