javascript - 不使用 jQuery 发送不和谐 webhook
问题描述
我正在尝试在没有 jQuery 的情况下发送不和谐的 webhook 消息。我尝试了以下方法:
var sendWebhook = new XMLHttpRequest()
sendWebhook.open("POST", $("webhook")[0].value)
sendWebhook.onload = function() {
if(sendWebhook.status === 200) {
Leaderboard.sendMessage("Webhook sent!")
} else {
Leaderboard.sendMessage("Failed sending webhook...")
}
}
sendWebhook.send({
data: JSON.stringify({
content: "hi",
username: "hello",
avatar_url: ""
})
})
还有很多其他方法,但它总是失败!有什么问题?谢谢!!
解决方案
一个简短的,非面向对象的版本:
function discord_message(webHookURL, message) {
var xhr = new XMLHttpRequest();
xhr.open("POST", webHookURL, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
'content': message,
'username':'AI',
}));
}
推荐阅读
- vb.net - Visual Studio 在使用 Crystal 报表时抛出 System.Runtime.InteropServices.COMException: 'Exception from HRESULT: 0x800A5023'
- php - pChart 在主机服务器上工作,但在 XAMPP 上工作:未捕获的错误:不能将字符串偏移量用作数组
- svg - 如何给 SVG 文档起一个标题,其工作方式与
element in the <head> of an HTML document?</h1> <div id="body"><p>In an HTML document <code><head></code>, the <code><title></code> element declares the human-readab - sql - 不相关的表格和时间间隔
- r - R:如何在 CRAN 的小插图中包含静态 pdf?
- javascript - Webpack 4 未创建捆绑文件
- javascript - React-redux 应用程序没有延迟刷新存储
- java - MacOS Catalina(v 10.15.3):错误:无法打开“chromedriver”,因为无法验证开发者。无法启动 chrome 浏览器
- python - 如何打印我输入的所有值?
- css - Vuetify:自动完成组件的自定义页脚