2

I'm trying to call asmx service using AngularJS $http. But i'm unable to get data from web service. I'm getting a success callback, but the response is the entire html page instead of the object returned as response.

Here is my C# asp.net web service code:

public class DataService : System.Web.Services.WebService
{

    [WebMethod]
    public Hello HelloWorld()
    {
        Hello h = new Hello();
        h.Message = "Hello World";
        return h;
    }
}

public class Hello
{
    public string Message { get; set; }
}

And here is the AngularJS code

    function FormController($scope,$http) {

    $scope.submit = function (user) {
        var url = '../../Services/DataService.asmx?op=HelloWorld';
        $http({
            method: "get",
            url: url
        }).success(function (data, status, headers, config) {
            console.log(data);
        });
    }

    FormController.$inject = ['$scope','$http'];
}

the above method is called on form submit.

4

1 回答 1

0

看起来网址不正确。

尝试:

function FormController($scope,$http) {

    $scope.submit = function (user) {
        var url = '../../Services/DataService.asmx/HelloWorld';
        $http({
            method: "get",
            url: url
        }).success(function (data, status, headers, config) {
            console.log(data);
        });
    }

    FormController.$inject = ['$scope','$http'];
}
于 2014-06-20T09:49:05.007 回答