EXTJS + AJAX验证用户名是否存在
items:[{
fieldLabel:'用户名',
id:'username',
name:'user.username',
invalidText:'此用户已被注册',
validator:checkUser,
allowBlank:false,blankText:'用户名不能为空'
}]
var isUserName = false;
function checkUser(){
Ext.Ajax.request({
url:'',
method:'post',
params:{
username:Ext.getCmp('username').getValue()
},
success:function (response,options){
var result = Ext.util.JSON.decode(response.responseText);
if(result.success == true){
isUserName = true;
}else{
isUserName = false;
}
}
});
return isUserName;
}
items:[{
fieldLabel:'用户名',
id:'username',
name:'user.username',
invalidText:'此用户已被注册',
validator:checkUser,
allowBlank:false,blankText:'用户名不能为空'
}]
var isUserName = false;
function checkUser(){
Ext.Ajax.request({
url:'',
method:'post',
params:{
username:Ext.getCmp('username').getValue()
},
success:function (response,options){
var result = Ext.util.JSON.decode(response.responseText);
if(result.success == true){
isUserName = true;
}else{
isUserName = false;
}
}
});
return isUserName;
}