【发布时间】:2017-04-06 16:34:49
【问题描述】:
我有一个 JSON 数组,我正在尝试使用 Ajax 将其发布到 SENDGRID。使用 Postman,我可以毫无问题地发布,但是当我在 .js 文件中发布数据时,我不断收到错误消息(错误请求 = 缺少参数)。
感谢任何帮助。
注意:这些值实际上是有效的。为了安全起见,我删除了识别信息。
铬负载:
AJAX 调用:
var mailUrl = "https://api.sendgrid.com/v3/mail/send";
var postdata = '{"personalizations": [{"to":[{"to email"}],"from": {"email":"from email"},"subject":"Hello, World!" , "content" : [{ "type":"text/plain" , "value":"TestMessage!" }]}]}'
$.ajax({
type: 'POST',
headers: {Authorization: "Bearer APIKEY"},
url: mailUrl,
contentType: "application/json",
data: JSON.stringify(postdata),
success: function (res) {
alert('ok');
},
error: function (res) {
alert('problems');
}
});
【问题讨论】:
标签: javascript jquery ajax post sendgrid