我正在努力使用以下代码。发送请求但不调用回调。我也没有收到任何错误,但发送了电子邮件!你有什么想法吗?
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);
}
});
});
答案 0 :(得分:2)
您已将选项对象分成两个独立的对象:
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);
}
});