【问题标题】:AngularJS, do POST then GET requestAngularJS,做 POST 然后 GET 请求
【发布时间】:2015-01-29 00:19:55
【问题描述】:

我已经在AngularJS, factory, do POST then GET method 上提出了这个问题。我必须像{'exp':'2+3','token':'asd'}那样做POST请求获取json(SoluableNonagon回答我很好),然后从json获取令牌并获取像/something/:token这样的请求,在此之前我必须检查json中是否存在令牌我用 POST 方法得到的。谁能告诉我该怎么做以及如何从正在执行发布请求的控制器调用工厂?

【问题讨论】:

    标签: json angularjs rest


    【解决方案1】:

    每个$http函数都会返回一个promise,promise可以嵌套或序列化函数内部的return必须是promise才能序列化你的操作,下一个then将在$http.get最终完成时调用。

    $http.post('post1').then(function (resultPost1) {
    
       // do your stuff
    
       return $http.get('get1');
    
    }).then(function (resultGet1) {
    
       // do your stuff
    
       return $http.get('get2').then(function (resultGet2) {
    
           // do your nested stuff
    
           return $http.get('get3');
       });
    
    }).then(function (resultGet3) {
    
        // do your stuff
    
    });
    

    有关 $q 文档的更多信息:https://github.com/kriskowal/q

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-05
      • 2018-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-24
      相关资源
      最近更新 更多