java 中使用ajax调用后台方法注意事项

java 中使用ajax调用后台方法注意事项,后台方法一定要加@ResponseBody

    jQuery.validator.addMethod("checkRuleName",function(value, element) {
var rst = false;
//校验规则组合名称是否重复
$.ajax({
type : "post",
cache : false,
async: false,//
url: '${ctx}/ProductPackageRule/Contro/checkRuleName',
//?groupName='+value
data:{'ruleName':value},
success : function(result) { if(result=="0")
{
rst = true;
}
}
}); return rst;
},"规则名称重复!");

后台代码:

@RequiresPermissions("/ProductPackageRule/Contro:view")
@RequestMapping(value ="checkRuleName", method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody //一定要记得加上
public int checkRuleName(String ruleName)
{
int k=1;
ProductPackageRuleModel model = new ProductPackageRuleModel();
model.setRuleName(ruleName);
List<ProductPackageRuleModel> list = productPackageRuleDao.checkRuleName(model);
if (list.isEmpty()) {
k=0;
}
return k;
}
上一篇:C#调用Java方法


下一篇:Mac下的开发工具