1. 程式人生 > >angularJS1 提交form表單demo

angularJS1 提交form表單demo

demo.html

<!doctype html>
<html>

    <head>
        <meta charset="utf-8">
        <title>form demo</title>
        <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
        <script type="text/javascript"
src="js/angular.min.1.6.0.js">
</script> </head> <body ng-app="app" ng-controller="myctrl"> <form ng-submit="submitForm()"> <div id="name" > <label>姓名(暱稱)</label> <input type="text" name="name" placeholder
="name" ng-model="user.name">
</div> <div id="phone" > <label>手機號碼</label> <input type="text" name="phone" placeholder="phone" ng-model="user.phone"> </div> </form> <p >
{{user.name
+","+user.phone}}
</p> </body> <script> var formApp = angular.module('app', []); formApp.controller("myctrl", function($scope, $http) { $scope.user= {}; $scope.submitForm = function() { $http({ method: 'POST', url: 'https://101.231.204.80:5000/gateway/api/frontTransReq.do', data: $.param($scope.user), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .success(function(data) { console.log(data); }); }; }); </script> </html>