我對API和ES6很陌生。我將如何發佈用戶名和密碼,並在不正確的情況下獲得回覆。順便說一句,這個網站不工作。 如何使用ES6獲取API
fetch('http://thisissamplewebsite.com', {
method: 'post',
body: JSON.stringify({
email: document.getElementById('email').value
answer: document.getElementById('answer').value
})
});
<!DOCTYPE html>
<html>
<head>
<title>Consume API</title>
</head>
<body>
<form method="POST">
<input type="email" id="email" placeholder="email" value="[email protected]"/>
<input type="password" id="password" placeholder="password" value="12345"/>
<input type="submit" value="Submit">
</form>
</body>
</html>
你在你的HTML代碼 – Colin
拼寫錯誤的方法,他們有取一個非常好的文檔。看這裏https://github.github.io/fetch/ – Colin
@Colin。你能幫我構造這個代碼嗎? – Joseph