【问题标题】:Callback is not called after execution without any errors执行后不调用回调,没有任何错误
【发布时间】:2015-06-22 16:47:44
【问题描述】:

我正在为以下代码而苦苦挣扎。请求已发送,但未调用回调。我也没有收到任何错误,但已发送电子邮件!你有什么想法吗?

var userPointer = webhook.get("user");
userPointer.fetch().then(function(user){

    Parse.Cloud.httpRequest({ 
        method: 'POST', 
        headers: {
            'Content-Type': 'application/json; charset=utf-8'
        }, 
        url: 'https://mandrillapp.com/api/1.0/messages/send-template.json', 
        body: {
            template_name: webhook.get("mandrillTemplateSlug"),
            template_content: null,
            key: user.get("apiKey"),
            message: {
                subject: webhook.get("subject"),
                from_email: "example@mail.com",
                from_name: "System",
                to: userData
            },
            async: false
         }
    },{
        success: function(httpResponse) {
            console.log(httpResponse);
        },
        error: function(error){
            console.log(error);
        }
    });
});

【问题讨论】:

    标签: javascript parse-platform mandrill


    【解决方案1】:

    您已将选项对象分成两个单独的对象:

    Parse.Cloud.httpRequest({
        method: 'POST',
        headers: {
            'Content-Type': 'application/json; charset=utf-8'
        },
        url: 'https://mandrillapp.com/api/1.0/messages/send-template.json',
        body: {
            template_name: webhook.get("mandrillTemplateSlug"),
            template_content: null,
            key: user.get("apiKey"),
            message: {
                subject: webhook.get("subject"),
                from_email: "example@mail.com",
                from_name: "System",
                to: userData
            },
            async: false
        }
    }, { // <=== Remove these, replace with just a comma
        success: function(httpResponse) {
            console.log(httpResponse);
        },
        error: function(error) {
            console.log(error);
        }
    });
    

    应该只有一个,像这样:

    Parse.Cloud.httpRequest({
        method: 'POST',
        headers: {
            'Content-Type': 'application/json; charset=utf-8'
        },
        url: 'https://mandrillapp.com/api/1.0/messages/send-template.json',
        body: {
            template_name: webhook.get("mandrillTemplateSlug"),
            template_content: null,
            key: user.get("apiKey"),
            message: {
                subject: webhook.get("subject"),
                from_email: "example@mail.com",
                from_name: "System",
                to: userData
            },
            async: false
        },
        success: function(httpResponse) {
            console.log(httpResponse);
        },
        error: function(error) {
            console.log(error);
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2018-09-27
      • 2017-11-10
      • 2015-11-12
      • 1970-01-01
      • 2016-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多