在 HTML 中使用星座 API 对象

问题描述 投票:0回答:1

我正在创建一个使用星座 API 来生成星座的网站。我使用的 API 创建一个包含四个元素的 JSON 对象:sunsign、元、星座和日期。我想要使用的只是星座本身:由于 api 结果的 url 已经包含日期和符号,并且不需要元,因此没有必要让它变得更复杂。

API来自这个网站: http://theastrologer-api.herokuapp.com/api/horscope/taurus/today

我遇到的麻烦是引用对象的星座。我无法判断是否我对输出的格式设置不正确,因此网页无法显示它,或者引用本身是否有缺陷。如果有人能帮助我弄清楚并纠正它,我将不胜感激。

这是我当前的代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Your Daily Horoscope</title>
    <link rel="Stylesheet" media="all" href="styles.css" />
    <link rel="shortcut icon" type="icon/x-icon" href="icon.jpg" />
</head>

<body>
    <img class = "banner" src="horoscopebanner.jpg" />
    <h2>What's your day going to be? Find out now!</h2>
    <h4>If this is your first visit, scroll on down to your horoscope. Select your sign at from the bottom radial buttons, 
so when you join us next time, your horoscope will be at the top of the list!</h4>
<div class = "horoscopes" id="aries">
    <img class="signs" src="aries.jpg" alt="Aries Sign" align="left" />
</div>
<div class = "horoscopes" id="taurus" >
    <img class="signs" src ="taurus.jpg" alt="Taurus Sign" align="left" />
</div>
/* Rest of the signs and their horoscopes here */

<script>
var xmlhttp = new XMLHttpRequest();
var url = "http://theastrologer-api.herokuapp.com/api/horoscope/taurus/today";

xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        myFunction(xmlhttp.responseText);
    }
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
function myFunction(response) {
    var object = JSON.parse(response);
    var out = "<p>";
    out += object.horoscope + "</p>";
    document.getElementById("taurus").innerHTML = out;
}
</script>

</body>
</html>

预先感谢您提供的任何帮助。

html json oop api-design
1个回答
-1
投票

您当前的星座 API 实现似乎面临一些问题。如果您愿意探索替代方案,您可能会发现 DivineAPI.com 有帮助。我们的 API 专为无缝集成到数字平台而定制,并附带全面的文档来指导您完成设置。如果您在使用我们的占星术、塔罗牌和占星术 API 方面遇到任何障碍或有疑问,我们的团队随时准备为您提供帮助。请随时查看我们的文档或寻求任何说明。

© www.soinside.com 2019 - 2024. All rights reserved.