クライアント側で javascript を使用し、サーバー側で node.js を使用しています。実際には、入力フィールドのリモート検証を試みました。結果はブール値である必要があり、サーバー呼び出しに基づいている必要があります。私のコードは次のとおりです。
jQuery.validator.addMethod("remoteValidation", function(value, element) {
var accountName = $("#accountName").val();
var accountType = $("#accountType").val();
var valid = this.Validation(accountType,accountName);
//returning undefined becoz return statement executing before server side execution
return valid;
}, "Entered email or username already exists");
this.validation = function(accountType,accountName,cb){
var valid =null;
ss.rpc('AccountsManagement.userNameChecker',accountType,accountName,function(res) {
// res will return boolean
valid = res;
});
//valid is null becoz this line is executing before valid = res line.
return valid;
};
私のサーバー側のコード:
services.imAccountsService.getAllImAccounts(accountType,accountName,
function(err,result){
if(err){
return;
}
if(result == null){
res(true);
}
else{
res(false);
}
});
私の問題は非同期実行です。この状況でコードを同期させる方法..