在角度js项目中发布请求不成功?

时间:2016-01-21 16:07:36

标签: angularjs

**Here is my app.js**
 var app = angular.module("app", []);
    app.controller("HttpGetController", function ($scope, $http) {

        $scope.SendData = function () {
           // use $.param jQuery function to serialize data from JSON 
            var data = $.param({
                fName: $scope.firstName,
                lName: $scope.lastName
            });

            var config = {
                headers : {
                    'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
                }
            }

            $http.post('/PostRequest/RequestForm.html', data, config)
            .success(function (data, status, headers, config) {
                $scope.PostDataResponse = data;
            })
            .error(function (data, status, header, config) {
                $scope.ResponseDetails = "Data: " + data +
                    "<hr />status: " + status +
                    "<hr />headers: " + header +
                    "<hr />config: " + config;
            });
        };

    });

**here is my html**
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src = "js/app.js"></script>
<script src = "js/jquery.js"></script>
<body>
<div ng-app="app" ng-controller="HttpGetController">
    <p>First Name: <input type="text" name="firstName" ng-model="firstName" required /></p>
    <p>First Name: <input type="text" name="lastName" ng-model="lastName" required /></p>
    <button ng-click="SendData()">Submit</button>
    <hr />
    {{ PostDataResponse }}
    {{ ResponseDetails }}
</div>
</body>

我在eclipse中创建了一个dynamicwebproject。但是当我运行这个程序时,我得到了以下输出enter image description here 我不知道我是否在post post中传递了正确的url。我将Requestfrom.html作为输出。现在让我告诉我如何解决这个问题以及如何传递正确的url。

0 个答案:

没有答案