[英]AngularJS button submit not working
我试图从AngularJS调用Spring Restful服务POST方法。
下面是我的JSP。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
<script type="text/javascript">
var app = angular.module("UserManagement", []);
app.controller("UserManagementController", function($scope, $http) {
//Initialize page with default data which is blank in this example
$scope.policy = [];
$scope.form = {
id : -1,
firstName : "",
lastName : "",
email : ""
};
//HTTP DELETE- delete employee by Id
$scope.submitEmployee = function(policy) {
$http({
method : 'POST',
url : '/Add_Policy',
data : angular.toJson($scope.form),
headers : {
'Content-Type' : 'application/json'
}
}).then(_success, _error);
};
} );
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>MMS Ensure</title>
</head>
<body ng-app="UserManagement"
ng-controller="UserManagementController">
<h1>New Policy</h1>
<!-- https://dzone.com/articles/building-rest-service-collects -->
<!-- http://howtodoinjava.com/angularjs/angularjs-http-restful-api-example/ -->
<from ng-submit="submitEmployee()">
<table>
Policy #:
<input type="text" ng-model="Policy">
<br> Policy Type:
<input type="text" ng-model="Type">
<br> Policy Tenture
<input type="text" ng-model="Tenture">
<br> Start Date:
<input type="text" ng-model="SDate">
<br> Holder Name:
<input type="text" ng-model="HName">
<br> Age:
<input type="text" name="Age">
<br>
<input type="submit">
</table>
</from>
</body>
</html>
如果我按提交按钮,它不会调用我的服务。 请帮忙
更多信息:我在本地运行,并在同一项目中提供Spring服务。 我试图在浏览器控制台中访问$ scope,它抛出错误说它未定义。
你让错字,其form
元素不from
<from ng-submit="submitEmployee()">
应该
<form ng-submit="submitEmployee()">
其他的东西是技术上table
中不能有其他元素直接指望tbody
, tr
, tfoot
, thead
, td
等(它们可以位于td
/ th
)。 您拥有的当前HTML错误且无效。
如果你做检查元素,你会发现, html
是有内table
必须在外面抛出table
元素。
我没有看到你需要table
元素的任何理由。 您只需删除table
元素包装器即可。
有错字,应该是
<form ng-submit="submitEmployee()">
<table>
<thead>
<tr>
<td>
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
</td>
</tr>
</tfoot>
</table>
将控制器和html保存在单独的文件中是很好的做法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.