代码拉取完成,页面将自动刷新
<script>
document.addEventListener("DOMContentLoaded", function () {
getRandomQuote();
function getRandomQuote() {
fetch('http://localhost:8080/?lang=cn') // Replace this with your deployed API URL; change to 'en' for English quotes
.then(response => response.json())
.then(data => {
if (data.error) {
document.getElementById('quote').innerText = 'Loading failed, please try again later';
} else {
document.getElementById('quote').innerText = data.quote;
}
})
.catch(error => console.error('Error:', error));
}
});
</script>
<div id="quote">Loading...</div>
In this section, you are guided on how to integrate SZSK's Daily Quote API into an HTML page. When the page is loaded, the getRandomQuote
function will be executed, which sends a request to the API (with the language parameter set as Chinese). The fetched quote is then displayed within a div
element with the ID 'quote'
. If there's an error while fetching the quote, it displays a message saying 'Loading failed, please try again later'. To request an English quote, simply replace 'lang=cn'
with 'lang=en'
in the fetch URL.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。