$(function(){
$("#myform").validate({
rules:{
code:{required:true,remote: "<%=request.getContextPath()%>/Payment/CheckExisted",minlength:4},//minlength最小值,下面的鼠標點擊事件加的0000不能大於此值
},
messages:{
code:{required:"請輸入編號",remote:jQuery.validator.format("此编号已被使用"),minlength:"請输入編號"},
}
});
$("#code").blur(function(){
if( $.trim($(this).val())=='') return;
var val ="0000"+$(this).val();
val = val.substr(val.length-4,4);
$(this).val(val);
$(this).keyup();
});
$("#freeDef,#maxAmt,#code").onlypressnum();
if ($(".interval_tip").length > 0) {
setTimeout(function() {
$(".interval_tip").fadeOut();
}, 5000);
}
/* parent.$('#dg').datagrid('reload'); */
});
////CouponController裡的函數//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@RequestMapping(value="Coupon/CheckExisted",method=RequestMethod.POST)
public void CheckExisted(Coupon coupon,HttpServletResponse response,@RequestParam("code") String code){
try {
String res="false";
if(null!=code){
String codee ="00000000" +code.trim();
String codeee=codee.substring(code.length());
/*System.out.println(codee+"@@@@"+codee.length());*/
System.out.println(codeee);
Coupon ks = CouponService.getCouponById(codeee);
if(null==ks)
res="true";
}
response.setHeader("Content-type", "text/json;charset=UTF-8");
// 如果是默認繁體中文查看,則設置為UTF-8.
response.setCharacterEncoding("UTF-8");
response.getWriter().write(res);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}