var url = "/test/check";
$.ajax({
type: "post",
url: url,// data: "para="+para, 此处data可以为 a=1&b=2类型的字符串 或 json数据。
data: {"para":1},
cache: false,
async : false,
dataType: "json",
success: function (data ,textStatus, jqXHR)
{ if("true"==data.flag){
alert("合法!"); return true;
}else{
alert("不合法!错误信息如下:"+data.errorMsg); return false;
}
},
error:function (XMLHttpRequest, textStatus, errorThrown) {
alert("请求失败!");
}
});/**
* 校验
*
* @return void */
public void check(){
Map<String,String> result = new HashMap<String,String>(); boolean flag = false; try{
String para= getPara("para"); //校验 代码...
result.put("flag", "true");
renderJson(result);//返回json数据
}catch(Exception e){
result.put("flag", flag+"");
result.put("errorMsg", e.getMessage());
renderJson(result);//返回json数据
e.printStackTrace();
}
}
温馨提示:答案为网友推荐,仅供参考