1 Star 3 Fork 0

孙子烧烤 / 每日一言

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
HTML.en.md 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
孙子烧烤 提交于 2024-01-30 18:41 . 添加文件

Using SZSK Daily Quote API in HTML Pages

Add the script code at any desired location

<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>

Call the API at the appropriate place

<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.

Go
1
https://gitee.com/szsk/yiyan.git
git@gitee.com:szsk/yiyan.git
szsk
yiyan
每日一言
master

搜索帮助