angular-$http注册功能

xiaoxiao2021-02-27  570

<!DOCTYPE html> <html ng-app="myApp"> <head>     <meta charset="UTF-8">     <title>Title</title>     <script src="js/angular/angular.min.js"></script> </head> <body> <div class="form" ng-controller="login">     账号:<input type="text" ng-model="username"><br />     密码:<input type="text" ng-model="password"><br />     <button ng-click="loginFn2()">注册</button> </div> <script>     var app = angular.module("myApp", []);     app.controller("login", ["$scope", "$http",         function($scope, $http) {             $scope.loginFn2 = function() {                 // 实现登录                 $http({                     method:"GET",                     url:"http://datainfo.duapp.com/shopdata/userinfo.php",                     params:{status:"login",userID:$scope.username,  password:$scope.password}                     /*                     如果是get请求,请使用params来传递参数                     如果是Post请求,请使用data来尝试传递参数                      */                 }).then(                     function success(resp) {                         console.log("请求成功", resp);                         if(resp.data==1) {                             console.log("注册成功"); //                            $location.path("/login")   跳转                         }else if(resp.data==0){                             console.log("用户名重名,请重新输入用户名");                         }else {                             console.log("系统繁忙请 稍后再试");                         }                     },                     function error(resp){                         console.log("请求失败");                     }                 );             }     }]); </script> </body>

</html>

参数:

status:register

userID:用户名

password:密码

返回值

用户名重名:0

注册成功:1

数据库报错:2

转载请注明原文地址: https://www.6miu.com/read-568.html

最新回复(0)