function save(){
if($("#ID").val()==""){
$("#ID").tips({
side:3,
msg:'请输入媒体类型ID',
bg:'#AE81FF',
time:2
});
$("#ID").focus();
return false;
}
if($("#ID").val()){
var flag=validateID($("#ID").val())
if(flag){
freshID();
}
}
function validateID(id){
$.ajax({
url:'validate_id',
data:{id:$("#ID").val()},
dataType:'json',
type:'post',
success:function(resp){
return resp.msg
}
});
}
function freshID(){
$.ajax({
url:'fresh_id',
dataType:'json',
type:'post',
success:function(resp){
$("#ID").val(resp.ID)
}
});
controller中代码
/**
* 保存前校验
* @param sitecode
* @return
* @throws Exception
*/
@RequestMapping(value="/validate_site_code")
@ResponseBody
public Object validateSiteCode(String sitecode) throws Exception {
PageData pd = new PageData();
Map<String,Object> map = new HashMap<String,Object>();
pd = this.getPageData();
if (siteService.hasThisCode(sitecode)) {
map.put("msg", "true");
}else{
map.put("msg", "false");
}
return AppUtil.returnObject(pd, map);
}
/**
* 刷新站点代码
* @return
* @throws Exception
*/
@RequestMapping(value="/fresh_site_code")
@ResponseBody
public Object freshSiteCode() throws Exception {
PageData pd = new PageData();
Map<String,Object> map = new HashMap<String,Object>();
pd = this.getPageData();
map.put("SITE_CODE", getNextSiteCode());
return AppUtil.returnObject(pd, map);
}