Get one sentence of the day to be displayed in the blog
One api per day
https://api.xygeng.cn/one
Response result
{
"code": 200,
"data": {
"id": "807",
"tag": "漫画",
"origin": "《萤火之森》",
"content": "其实美丽的故事都是没有结局的,只因为它没有结局所以才会美丽。",
"datetime": "1548230343"
}
}
use
html
<div class="sentence">
<strong>每日一句</strong>
<h2 class="one_datetime">自动获取</h2>
<p class="one_content">自动获取</p>
</div>
ajax send get request and add data
<script>
{
#
{
#function getFormatDate(str) {
#}
{
# var oDate = new Date(str),#}
{
# oYear = oDate.getFullYear(),#}
{
# oMonth = oDate.getMonth() + 1,#}
{
# oDay = oDate.getDate(),#}
{
# oHour = oDate.getHours(),#}
{
# oMin = oDate.getMinutes(),#}
{
# oSen = oDate.getSeconds(),#}
{
# oTime = oYear + '-' + oMonth + '-' + oDay;
{
# return oTime;#}
{
# };#}
$.ajax({
url: 'https://api.xygeng.cn/one',
type: 'get',
success: function (data) {
{
#console.log(data)#}
if(data.code==200){
var content = document.createTextNode(data.data.content)
{
#var date = getFormatDate(1550113467879)#}
{
#console.log(data.data.datetime)#}
{
#console.log(date)#}
$('.one_content').html(content)
$(function () {
var myDate = new Date;
var year = myDate.getFullYear();
var mon = myDate.getMonth() + 1;
var date = myDate.getDate();
var week = myDate.getDay();
var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
{
#console.log(year, mon, date, weeks[week])#}
$(".one_datetime").html(year + "年" + mon + "月" + date + "日" + weeks[week]);
})
}
}
})
</script>