【问题标题】:how to return a response from a Parse.com Cloud Code Module?如何从 Parse.com 云代码模块返回响应?
【发布时间】:2015-11-25 13:22:58
【问题描述】:

从 parse.com 示例中,我在 cloud/module.js 中有

module.exports = {

...

search: function(params, options) {
  return Parse.Cloud.httpRequest({
    method: "GET",
    url: "https://externalapi.com"
  }).then(function(httpResponse) {
    console.log(httpResponse.text); //<--- THIS WORKS!
    if (options && options.success) {
      options.success(httpResponse);
    }
  }, function(httpResponse) {
    if (options && options.error) {
      options.error(httpResponse);
    }
  });
}

代码有效,我可以在解析代码中看到响应控制台日志。

它说options 是未定义的,所以它永远不会调用options.success

那么这个,总是返回空

在 cloud/main.js 中

Parse.Cloud.define("searchIt", function(request, response) {
  myModule.search({
        near: request.params.near,
        query: request.params.query
  }).then(function(httpResponse) {
    response.success(httpResponse);
  }, function(httpResponse) {
    response.error("Uh oh, something went wrong");
  });
});

【问题讨论】:

    标签: javascript parse-platform


    【解决方案1】:

    我把代码改成了这样:

      return Parse.Cloud.httpRequest({
        url: 'https://externalapi.com',
        success:function(httpResponse){
    
        },
        error:function(httpResponse){
    
        }
      });
    }
    

    现在正在工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 2016-05-04
      • 1970-01-01
      • 2019-02-16
      相关资源
      最近更新 更多