使用POST的REST调用不显示响应消息

时间:2018-05-12 18:51:02

标签: html angularjs 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>

0 个答案:

没有答案