angularjs - Angular js and ionic -
how post html login form php login form in different url using angular js controller , returning success when login credential correct , failure when credentials wrong.below existing controller , intends use html login page while posts/authenticates login.php , returns success or failure upon input credentials
.controller('loginctrl', function ($scope, $state, $ionicviewservice, $http, datastore) { $scope.domain = datastore.domain; var urlpath = datastore.domain+'/login.php'; $("#username").focus(); $("#username, #password").keyup(function () { if ($(this).val().length !== 0) { $("#validate").hide(); } }); //authenticates blank fields $("#login").on('click', function () { if ($("#username").val() == '') { $("#validate").html("username required").show(); $("#username").focus(); } else if ($("#password").val() == '') { $("#validate").html("password required").show(); $("#password").focus(); } else { $.ajax({ type: "post", url: urlpath, data: $('#myloginform').serialize(), success: function (html) { var resp = html.split(":"); // alert(resp[0]); if (resp[0] == 'success') { $("#validate").html("wrong username or password").show(); }else { $state.go('menu.home'); } } }); // todo: login done here //todo: validate login $ionicviewservice.nextviewoptions({ disableback: true }); //$state.go('menu.home'); return false; }; }) })
have tried coding
else { $http.post('http://localhost:0000', data).success(successcallback); }
localhost ip or url of server wishing send post data to.
Comments
Post a Comment