【问题标题】:Rectangular addResponseInterceptor data object undefined while has it in response object矩形 addResponseInterceptor 数据对象未定义,而它在响应对象中
【发布时间】:2014-08-18 17:24:48
【问题描述】:

使用 Restangular,get 方法/promise 解决,但传递给 .then() 的结果是空的...使用 console.log(data);显示未定义。我在 chromium 调试中检查了网络选项卡,xhr 请求很好,成功了 200 次……正文中有完整的 json 响应。

使用addResponseInterceptor,我发现数据参数未定义,但响应参数显示包含有效负载/正文的数据属性的对象。

所以,我摸不着头脑.....为什么在响应对象正确包含 response.data 中的 json 有效负载/响应时数据参数未定义?

我需要解决这个问题,以便在解决时将结果传递给 .then()。

createNode: function(node) {
      var account = "9936";
      var eventId = "0fd6afd9-4aa0-a5c9-ff0b3e60cdcf";
      Restangular.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
          console.log("````````````````");
          console.log(data);
          console.log(operation);
          console.log(what);
          console.log(url);
          console.log(response);
          console.log(deferred);
          console.log("````````````````");
      });

                                                                        node.js:12
undefined                                                               node.js:13
get                                                                     node.js:14
event                                                                    node.js:15
/1.0/loadbalancers/account/9936/event/0fd6afd9-4aa0-a5c9-ff0b3e60cdcf    node.js:16
^Object {data: Object, status: 200, headers: function, config: Object}
 config: Object
 data: Object
 Automation: Object
 Classification: Array[2]
 ExecutionTimestamp: "2014-08-13T16:08:37.4676Z"
 ID: "0fd6afd9-a5c9-ff0b3e60cdcf"
 Incident: Object
 LastStatus: "ENQUEUED"
 Metadata: Object
 Name: "Node Create"
 RecordLogs: false
 Source: "Device Lifecycle"
 Stream: Object
Targets: Array[1]

【问题讨论】:

    标签: angularjs restangular


    【解决方案1】:

    确保您的所有响应拦截器最后都返回数据:

    Restangular.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
      // your code here
    
      return data;
    });
    

    不返回任何内容会将数据设置为undefined 在后续响应拦截器调用中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-07
      • 2019-03-21
      • 2020-11-23
      • 2017-08-27
      • 2020-06-08
      • 2015-11-02
      • 2019-08-23
      • 2019-07-01
      相关资源
      最近更新 更多