繁体   English   中英

使用AngularJS进行异步调用

[英]Async calls using AngularJS

我们正在使用Angular发出多个HTTP请求:

$scope.GetTest1 = function () {
    $http.get("/test/GetTest1/").success(function (response) {
        $scope.res = response.aaData;
    });
} 

$scope.GetTest2 = function () {
    $http.get("/test/GetTest2/").success(function (response) { 
        $scope.res = response.aaData; 
    });
}

$scope.GetTest3 = function () {
    $http.get("/test/GetTest3/").success(function (response) { 
        $scope.res = response.aaData; 
    });
}

// This is called from an onclick of a button
$scope.LoadAll = function () {
    $scope.GetTest1();
    $scope.GetTest2();
    $scope.GetTest3();
}

我们假设所有这些都称为异步,但是,我们启用了log4net并记录了接收到“ gets”的日期时间,而这三个时间均为:

19时05分26秒

19时05分27秒

19时05分28秒

这是一个意外的惊喜,因为我们认为时间都在1秒以内。 即异步。

不知道我们是否缺少什么,

抱歉,问题是,我们如何进行这些异步调用?

我想可能是在服务器端。 当服务器只能处理来自一个客户端的一个请求时,我得到的结果几乎相同。 如果来自服务器的响应在一秒钟内满足了您的$http请求,则可能是一个问题。 请检查您的网络统计信息,如果您看到它们同时被调用但没有立即得到服务,则这是服务器端问题。

您可以在浏览器的devtools的时间轴上轻松跟踪

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM