关于Javascript FETCH API的非常愚蠢的问题

时间:2019-12-27 14:34:37

标签: javascript fetch-api

我正在学习javascript,目前正在学习fetch API。我读了一篇有关代码获取API的有趣文章:

// main.js 

// GET request using fetch() 
fetch("https://jsonplaceholder.typicode.com/users") 
	
	// Converting received data to JSON 
	.then(response => response.json()) 
	.then(json => { 

		// Create a variable to store HTML 
		let li = `<tr><th>Nama</th><th>Email</th></tr>`; 
		
		// Loop through each data and add a table row 
		json.forEach(user => { 
			li += `<tr> 
				<td>${user.name} </td> 
				<td>${user.email}</td>		 
			</tr>`; 
		}); 

	// Display result 
	document.getElementById("users").innerHTML = li; 
}); 
<!DOCTYPE html> 
<html lang="en"> 
<head> 
	<title>Fetch API</title> 
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head> 
<body> 
	<div> 
	<!-- Table to display fetched user data -->
	<table style="width: 50%;" border="1" id="users"></table> 
	</div> 
	
	<!-- Link JavaScript file -->
	<script src="main.js"></script> 
</body> 
</html> 

我正在尝试使用远程API进行一个三列的项目

https://ptini-nodejs.appspot.com/api?id=1Vo8shKHZ3Q8zA3yw0AY6D_nfQbTqbrNS5Ftbw0wX7xQ&sheet=1

如何制作?

0 个答案:

没有答案