从aspx到angularjs获取字符串数据返回undefined

时间:2016-10-05 14:29:04

标签: javascript c# asp.net angularjs json

我正在尝试使用aspxAngularJS后端到http post获取字符串,但它返回undefined。 这是我的代码

<body data-ng-app="myapp">
<div data-ng-controller="MyController" >
    <button data-ng-click="myData.doClick(item, $event)">Send AJAX Request</button>
    <br/>
    Data from server: {{myData.fromServer}}
  </div>
<script>
      angular.module("myapp", [])
          .controller("MyController", function ($scope, $http) {
              $scope.myData = {};
              $scope.myData.doClick = function (item, event) {
              $http.post('KeyPhraseGroup.aspx/GetEmployees', { data: {} })
                .success(function (data, status, headers, config) {
                    $scope.myData.fromServer = data.d;
                    console.log($scope.myData.fromServer);
                })
                .error(function (data, status, headers, config) {
                    $scope.status = status;
                });
           }
      }).config(function ($httpProvider) {
          $httpProvider.defaults.headers.post = {};
          $httpProvider.defaults.headers.post["Content-Type"] = "application/json; charset=utf-8";
      });

以下是我的c#方法

    [WebMethod]
    public static string GetEmployees()
    {
        return "OK-test";
    }

参考Get Json Data From Asp.Net Webmethod and Consume in angularJS

0 个答案:

没有答案