在做web开发中常遇到需要验证ID啊,用户名之类的是否已经存在,或者需要校验一些东西然后返回前台
直接上代码
Ext.Ajax.request( {
timeout : 3000000,
url : 'isexist.action',
params : 'id='+ encodeURI(ids)+'&descr='+encodeURI(descr),
success : function(response, config) {
json = Ext.JSON.decode(response.responseText);
if(json.message=='exist'){
Ext.Msg.alert('提示','名称['+json.bdescr+']已存在');
}else if(json.message=='ok'){
//成功之后所需的操作
},
failure : function(form,action) {
}
});
后台需要ACTION返回的json字符串
if(!exist){
response.getWriter().write("{'message':'exist',bdescr:'"+new String(descr.getBytes("UTF-8"),"ISO8859-1")+"'}");
return null;
}else{
response.getWriter().write("{'message':'ok'}");
return null;
}