javascript - 我如何获取 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>
解决方案
推荐阅读
- python - spark df中是否有可以被applymap替换的函数?
- java - 如何为测试启用“--enable-preview”?
- python - 为什么后面的 Python 函数定义在稍后调用时会产生“'NoneType' object is not subscriptable”错误?
- python - 无法访问类变量python
- java - 从 Spring Data Elastic Search 4.0.0 的 SearchHits 类中获取 InnerHits 结果
- r - 如何用 R 语言运行这个 MATLAB 的命令?
- java - 如何处理卡片视图中的不同按钮 onclick 和传递意图?
- python - 如何在 discord.py rewrite 中获取成员数?
- typescript - 打字稿推断该字段是真实的(不能未定义),没有用户定义的类型保护
- powerbi - DAX 中的 DATEDIFF 函数问题