来自 html 的 REST API 调用不工作

REST API call from html not working

我正在尝试从嵌入到我的 html 文件中的脚本调用 REST API post 函数。由于某种原因,该按钮无法正常工作,到目前为止,没有任何在线资源对我有帮助。此 html 代码将通过电子邮件发送,使用 outlook 的人打开电子邮件并单击 link 以调用其余 api。

这里是 html 代码:

<a href="#" onclick="markAsDone();" target="_blank" style="font-size: 16px; font-family: Helvetica, Arial, sans-serif; font-weight: normal; color: #ffffff;    text-decoration: none; display: inline-block;">I am done. &rarr;</a>
<script type="text/javascript">
function markAsDone() {
    var xhttp = new XMLHttpRequest();
    xhttp.open("POST", "http://localhost:1337/UserDone", false);
    xhttp.sendRequestHeader("Content-type", "application/json");
    xhttp.send();
}
</script>

我是不是做错了什么,或者 outlook 不兼容包含 html 和 link 这样的电子邮件?

我认为电子邮件客户端不支持使用 Javascript。我建议您在电子邮件中创建一个普通的 link,例如到 http://example.com/email/index.php,并在那里进行 API 调用。