首页 > 解决方案 > 我如何获取 API 以显示问题

问题描述

我已经开始学习 fetch API 几天了,我的老师让我立即学习。他说对数据的要求是没有的。它响应创建成功后,状态为 201,新创建的尝试包含尝试 ID 和 Data(Json) 中的一系列问题。我试图编码,但它不起作用。这是 API 的链接:https ://wpr-quiz-api.herokuapp.com/attempts

所有的描述都在这里。 https://wpr-quiz-api.herokuapp.com/

对不起我的英语不好,代码也不是很好,因为我刚开始学习它。因此,如果您不介意,请尽可能详细地描述。

太感谢了

let question=[];
const inputk = document.querySelector('span');
  question.push(inputk.value);
function onResponse(response){
  return response.json();
}
function onsubmit(object){
  const inputk = document.querySelector('span');
 question=object;
}
  fetch("https://wpr-quiz-api.herokuapp.com/attempts")
  .then(onResponse).then(onsubmit)
<form action="https://wpr-quiz-api.herokuapp.com/attempts" method="POST">
  <div>
    <span></span>
  <input type="radio">
    <label>Option 1</label><br>
   <input type="radio">
    <label>Option 2</label><br>
    <input type="radio">
    <label>Option 3</label><br>
  </div>
</form>

标签: javascript

解决方案


推荐阅读