how to check if username exists in angularjs -


all username , password details present in oracle db. using servlets , jsp backend. when user name registered through java servlet, sits in oracle db.

now want check if existing username available. know making ajax call fetch info pass url? shall pass url pattern of servlet (example: url:'./getrecords') ? or there other way of doing it?

also using end servlet , jsp idea? wonder why people use node js , mondo db angular js.

my problem solved this: using php mvc framework angularjs.

i have written directive validating unique field (checking db). script: app.js

var base_url="http://localhost/mysystem/";     var angularapp = angular.module('angularapp', ['ngroute','angularcontrollers','uniquefield']);       angularapp.config(['$routeprovider', function($routeprovider){         $routeprovider             .when('/add_user', {                 controller : 'adduserctrl',                 templateurl : base_url+'angular/partials/add_user.php'             })             .otherwise({                 redirectto : '/dashboard'             });     }]);      //unique field   --creating directive     angular.module('uniquefield', [])     .directive('uniquefield', function($http) {       var toid;       return {         restrict: 'a',         require: 'ngmodel',         link: function(scope, elem, attr, ctrl) {            //when scope changes, check field.           scope.$watch(attr.ngmodel, function(value) {             // if there previous attempt, stop it.             if(toid) cleartimeout(toid);              // start new attempt delay keep             toid = settimeout(function(){               // call api echo "1" or echo "0"               $http.get(base_url+'controller/check_unique?check=' + value).success(function(data) {                  //set validity of field                 if (data == "1")                  {                     ctrl.$setvalidity('uniquefield', false);                 }                 else if (data == "0")                 {                     ctrl.$setvalidity('uniquefield', true);                 }               });             }, 200);           })         }       }     }); 

this html:

user name: <input required type="text"  ng-model="uname" name="uname" id="uname" unique-field  /><br/>     <span style="color:red" ng-show="form_add.uname.$dirty && form_add.uname.$invalid">         <span ng-show="form_add.uname.$error.required">user name required.</span>             <span ng-show="form_add.uname.$error.uniquefield">user name exists.</span>     </span> 

note: submit button gets disabled if username exists. hope might help.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -