Angular正在等待另一个请求启动

时间:2017-01-31 13:55:27

标签: angularjs ajax

在我的应用程序中,我需要请求保存一些数据(此请求有点慢),但用户可以同时执行另一个请求,当他这样做时,angular正在等待第一个请求(不是assync) 。如何在不等待其他请求的情况下做两个请求?

我的服务很慢:

app.service('PedSaveService',["$http", "$q","BASEURL",
                       function ($http, $q,BASEURL) {
                           var self = this;

                           self.Save = function (pedidoData) {
                               var deferred = $q.defer();                
                               $http({method: 'POST',async: true, url: BASEURL.REST_SAVE, headers: {'Content-Type': 'application/json;charset=utf-8'}, data : pedidoData})
                                   .success(function (response, status, headers, config) {
                                       deferred.resolve(response, status, headers, config);
                                   })
                                   .error(function (response, status, headers, config) {
                                       deferred.reject(response, status, headers, config);
                                   });

                               return deferred.promise;
                           }

1 个答案:

答案 0 :(得分:0)

self.Save = function(pedidoData) {
$http({
    method: 'POST',
    async: true,
    url: BASEURL.REST_SAVE,
    headers: {
        'Content-Type': 'application/json;charset=utf-8'
    },
    data: pedidoData
}).then(function(res) {
    return res;
}); }

您的服务代码应为此。

相关问题