我正在尝试使用 AngularJS $http
调用 asmx 服务。但我无法从网络服务中获取数据。我得到一个成功回调,但响应是整个 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 不正确。
尝试:
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'];
}
关于c# - 获取 html 作为响应而不是从 asmx 服务返回的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24323437/