Ajax 数据提交并且返回数据提示

HTML:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title>优惠券</title>
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <link rel="stylesheet" type="text/css" href="$!webPath/resources/newui/bootstrap-3.3.7-dist/css/bootstrap.css" />
        <link rel="stylesheet" type="text/css" href="$!webPath/resources/newui/css/animate.css" />
        <link rel="stylesheet" type="text/css" href="$!webPath/resources/newui/css/base.css" />
        <link rel="stylesheet" type="text/css" href="$!webPath/resources/newui/css/21.css" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" /> 
        <!-- <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> -->
        <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
        <style type="text/css">
            input[node-type=jsbridge]{ 
                      display:none; 
                    }
        </style>
    </head>

    <body>
        <div class="container">
            <div class="row ">
                <!-- <button id="scanQRCode" >扫描二维码</button>  -->
                <div class="col-xs-8"> <input type="text" name="youHui" id="youHui" value="" style="border-radius:15px; border:1px solid #ccc; line-height: 35px;text-align: center;" placeholder="请输入代金券号 " /></div>
                <div class="col-xs-3 text-center" style="margin-top: 10px; line-height: 37px;border-radius:5px; background: #f6846a; color: white;" οnclick="coupon_bundled_save();">绑定</div>
                <!-- <div class="col-xs-8"> <input id="ttt"/> </div> -->
            </div>
            <!-- <div class="row" style="margin-top: 12px;">
                <div class="col-xs-4 col-xs-offset-4 text-center"  >    
                             代金券
                </div>

            </div> -->
            #if($!objs.size()>0)
              #foreach($obj in $objs)
                  <input id="users" value="$!{obj.user.userName}" type="hidden" />
            <div class="row" style="margin-top: 12px;">
                <div class="col-xs-10 col-xs-offset-1 " style=" background: url($!webPath/resources/newui/img1/beijing1.png)no-repeat; background-size: 100% 100%; color: #FFFFFF; position: relative; padding-top: 5px;">
                    <span>代金券号:$!obj.coupon_sn</span>
                    <p>价值:<span style="font-size: 20px;">$!{config.currency_code}$!obj.coupon.coupon_amount</span>代金券</p>
                    <p>订单满$!{obj.coupon.coupon_order_amount}可使用</p>
                    <p>有限期至:$!obj.coupon.coupon_begin_time----$!obj.coupon.coupon_end_time</p>
                    <!-- <img src="$!webPath/resources/newui/img/logo.png" style="max-height: 40px; position: absolute; bottom: 5px;; right: 8px;"/>     -->                            
                </div>            
            </div>    
               #end
             #else
                 <div class="row" style="margin-top: 12px;">
                <div class="col-xs-12" >                    
                    <div class="row daiJinquan" style="margin-top: 12px;">
                        <img src="$!webPath/resources/newui/img/yhqtishi.jpg" class="img-responsive">
                    </div>                            
                </div>            
            </div>
             #end
             <input id="appid" type="hidden" value="${appId}" />
             <input id="timestamp" type="hidden" value="${timestamp}" />
            <input id="noncestr" type="hidden" value="${nonceStr}" />
            <input id="signature" type="hidden" value="${signature}" />
    </body>
 
    <script src="$!webPath/resources/newui/js/jquery-3.1.1.js " type="text/javascript " charset="utf-8 "></script>
    <script src="$!webPath/resources/newui/bootstrap-3.3.7-dist/js/bootstrap.min.js " type="text/javascript " charset="utf-8 "></script>
    <script src="$!webPath/resources/newui/js/base.js" type="text/javascript " charset="utf-8 "></script>
    <script src="$!webPath/resources/newui/js/jquery-1.11.3.min.js" type="text/javascript " charset="utf-8 "></script>
    
<script> 
        function coupon_bundled_save() {
            var id = jQuery("#youHui").val();
            var users = jQuery("#users").val();
            var invoiceType = jQuery(":radio[id=invoiceType][checked=true]").val();
            jQuery.ajax({
                type : 'POST',
                dataType: "json",
                url : '$!webPath/admin/coupon_bundled_save.htm',
                data : {
                    "coupon_sn" : id,
                    "users":users
                },
                success: function(data) {
                    if (data.tishi == "1") {
                        alert("券号为空,请输入有效券号!");
                    }
                    if (data.tishi == "2") {
                        alert("券号已被使用!");
                    }
                    if (data.tishi == "3") {
                        alert("恭喜,绑定成功!");
                        window.location.href = "$!webPath/buyer/coupon.htm";
                    }
                },
            });
        }
    </script> 

</html>

JAVA:

@SecurityMapping(display = false, rsequence = 0, title = "优惠券绑定保存", value = "/admin/coupon_send_save.htm*", rtype = "admin", rname = "优惠券管理", rcode = "coupon_admin", rgroup = "运营")
    @RequestMapping({ "/admin/coupon_bundled_save.htm" })
    public void coupon_bundled_save(HttpServletRequest request, HttpServletResponse response, String coupon_sn) throws IOException {
        ModelAndView mv = new JModelAndView("wap/ticket.html", this.configService.getSysConfig(),
                this.userConfigService.getUserConfig(), 1, request, response);
        String tishi ="0";
        if(coupon_sn.equals("")){
            tishi = "1";//券号为空,请输入有效券号!
        }else{
            //查询限制优惠券绑定次数,页面进行提示。
        Map params = new HashMap();
        params.put("coupon_sn", coupon_sn);
        List couponL = this.couponinfoService
                .query("select obj.coupon.id,obj.user.id,obj.status,obj.id from CouponInfo obj where obj.coupon_sn=:coupon_sn ", params, -1, -1);
        Object[] objArray = null;
        for(int i=0; i<couponL.size();i++){
                objArray = (Object[]) couponL .get(i);
           }
        String users = SecurityUserHolder.getCurrentUser().getUserName();
        params.clear();
        params.put("username", users);
        List<User> newuser = this.userService.query("select obj from User obj where obj.userName=:username", params, -1,
                -1);
        if(objArray[1].equals(newuser.get(0).getId())||objArray[2].toString().equals("1")||couponL.size()>=2){
            tishi = "2";//券号已被使用!
        }else{
            CouponInfo ci = this.couponinfoService.getObjById(CommUtil.null2Long(objArray[3]));
            ci.setStatus(1);
            this.couponinfoService.update(ci);
        Coupon coupon = this.couponService.getObjById(CommUtil.null2Long(objArray[0]));
        CouponInfo info = new CouponInfo();
        info.setAddTime(new Date());
        info.setCoupon(coupon);
        info.setCoupon_sn(coupon_sn);
        info.setUser((User) newuser.get(0));
        this.couponinfoService.save(info);
        tishi = "3";//恭喜,绑定成功!
            }
        }
        Object map = new HashMap();
        ((Map) map).put("tishi", tishi);
        PrintWriter writer = response.getWriter();
        writer.print(Json.toJson(map, JsonFormat.compact()));
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值