开机自检的 REST 呼叫不显示响应消息



>我正在尝试使用 AngularJS 进行 POST 调用,并通过获取响应消息、响应状态等来查看一切是否正常工作。

我想要的是查看我的 POST 是否正常并且服务呼叫没有问题。

编辑:语法错误已更正

angular.module('myApp', [])
.controller('myCtrl', function ($scope, $http) {
$scope.hello = {id: "1", name: "ERA"};
$scope.newId= "";
$scope.newName = "";
$scope.sendPost = function() {
var data = $.param({
json: JSON.stringify({
	id: $scope.newId,
name: $scope.newName
})
});
$http.post("http://localhost:8080/academi-co/resources/tags/languages/", data).success(function(data, status) {
$scope.hello = data;

if (response.data)
	$scope.msg = "Post Data Submitted Successfully!";
	}, function (response) {
	$scope.msg = "Service not Exists";
	$scope.statusval = response.status;
	$scope.statustext = response.statusText;
	$scope.headers = response.headers();
})
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app='myApp'>
<div ng-controller="myCtrl">
<form ng-submit="sendPost()">
<input ng-model="newId"/>
<input ng-model="newName"/>
<button type="submit">Send</button>
</form>
<p>{{hello.id}}</p>
<p>{{hello.name}}</p>
<p>Output Message : {{msg}}</p>
<p>StatusCode: {{statusval}}</p>
<p>Status: {{statustext}}</p>
<p>Response Headers: {{headers}}</p>
</div>
</body>

我更改了一些代码,也许可以试试这个。

angular.module('myApp', [])
.controller('myCtrl', function ($scope, $http) {
$scope.hello = {id: "1", name: "ERA"};
$scope.newId= "";
$scope.newName = "";
$scope.sendPost = function() {
var data = {
json: JSON.stringify({
id: $scope.newId,
name: $scope.newName
})
};
$http.post("http://localhost:8080/academi-co/resources/tags/languages/", data).success(function(data, status) {
$scope.hello = data;
if (response.data)
$scope.msg = "Post Data Submitted Successfully!";
}, function (response) {
$scope.msg = "Service not Exists";
$scope.statusval = response.status;
$scope.statustext = response.statusText;
$scope.headers = response.headers();
})
}
})

最新更新