【问题标题】:How do i set the value of a json var as a input from html如何将 json var 的值设置为 html 的输入
【发布时间】:2020-09-22 18:42:10
【问题描述】:

我尝试了很多东西但它不起作用,我试图让它发送一个不和谐的 webhook 但我无法得到它,我得到的最接近的是一个发布错误,我知道它是什么意味着或者如果它是我的 json var 这是我的代码或我拥有的代码

function sendMessage() {
  var textimput = document.getElementById("userInput");

  var request = new XMLHttpRequest();
  request.open(
    "POST",
    "https://discord.com/api/webhooks/1234567890/1234567890qwertyuiosdfghxcvbn"
  );

  request.setRequestHeader("Content-type", "application/json");
  var i = 0;

  var message = {
    content: "Text",
    embeds: [
      {
        title: "Title",
        description: "message",
        color: 16711680,
        footer: {
          text: "Footer",
        },
      },
    ],
  };

  message.embeds[0].description = textimput;
  request.send(JSON.stringify(message));
}

我有这样的输入集

<input id="userInput" placeholder="INSERT TEXT LINK HERE">

【问题讨论】:

  • 扩展一点“无法理解”。您的“POST 错误”的错误消息是什么?
  • 我希望它从 webhook 嵌入到我的不和谐服务器中,但它使描述空白
  • 尝试使用message.embeds[0].description = textimput代替message.embeds[0].description = textimput.value
  • 谢谢,我已经尝试了将近 5 个小时了!非常感谢

标签: javascript html json discord


【解决方案1】:

替换

var textimput = document.getElementById("userInput")

var textimput = document.getElementById("userInput").value

您发送的是输入元素而不是它的值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    相关资源
    最近更新 更多