如何使角度ajax调用同步?

时间:2016-03-10 04:58:22

标签: angularjs ajax

var SaveIdeaEvaluationForm = function (evaluationForm, ideaId, stageId, isEvaluated) {
            return $http({
                url: SparkApp.FormEvaluation.SaveIdeaEvaluationForm,
                method: "POST",
                contentType: "application/x-www-form-urlencoded",
                dataType: "json",
                data: {
                    "evaluationForm": evaluationForm,
                    "ideaId": ideaId,
                    "stageId": stageId,
                    "isEvaluated": isEvaluated
                }
            });
        };

默认情况下它是异步的,我们是否有任何属性可以设置为同步??

1 个答案:

答案 0 :(得分:1)

广泛鼓励异步使用$http服务。看到这种方法:

// Simple GET request example:
$http({
  method: 'GET',
  url: '/someUrl'
}).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
  }, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

https://docs.angularjs.org/api/ng/service/$http

如果出于某种原因,您不能这样做,请使用$ q库作为DrenP建议。

相关问题