API Integration Example: Displaying JSON Data in HTML
<!DOCTYPE html>
<html>
<head>
<title>API Integration Example: Displaying JSON Data in HTML</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h1>API Integration Example</h1>
<div id="apiResult">
<!-- API response will be displayed here -->
</div>
<script>
$(document).ready(function() {
// Make API request
$.ajax({
url: "https://api.example.com/endpoint",
method: "GET",
ddataType: "json",
success: function(response) {
// Display API response in the div with id "apiResult"
$("#apiResult").html(JSON.stringify(response));
},
error: function() {
// Handle error if API request fails
$("#apiResult").html("Error occurred while making API request.");
}
});
});
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/p9kM 著作权归作者所有。请勿转载和采集!