Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取html作为响应,而不是从asmx服务返回的对象_C#_Asp.net_Angularjs_Asmx_Angularjs Http - Fatal编程技术网

C# 获取html作为响应,而不是从asmx服务返回的对象

C# 获取html作为响应,而不是从asmx服务返回的对象,c#,asp.net,angularjs,asmx,angularjs-http,C#,Asp.net,Angularjs,Asmx,Angularjs Http,我正在尝试使用AngularJS$http调用asmx服务。但我无法从web服务获取数据。我得到了一个成功的回调,但是响应是整个html页面,而不是作为响应返回的对象 这是我的C#asp.net web服务代码: public class DataService : System.Web.Services.WebService { [WebMethod] public Hello HelloWorld() { Hello h = new Hello();

我正在尝试使用AngularJS
$http
调用asmx服务。但我无法从web服务获取数据。我得到了一个成功的回调,但是响应是整个html页面,而不是作为响应返回的对象

这是我的C#asp.net web服务代码:

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; }
}
这是AngularJS代码

    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'];
}

在表单提交时调用上述方法。

看起来URL不正确

尝试:


您尝试过URL“../../Services/DataService.asmx/HelloWorld”了吗?现在,它在控制台中抛出错误
请求格式无法识别,因为URL意外地以“/HelloWorld”结尾。
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'];
}