weixin_33698823 2017-06-06 23:50 采纳率: 0%
浏览 20

AJAX供电的数据驱动应用

When I type in an artist and I click the button, I should get a nice list of their songs in a format that is aesthetically pleasing.

My error is: Nothing is returns whenever I press the button, I don't know why that is.

HTML File

<!DOCTYPE html>
<html>
<head>
    <title>Songs</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet"     href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script
    src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
    </script>
    <script
    src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
    </script>
    <script src="ajaxfunctions.js"></script>
</head>
<body>
    <div class="container">
        <h2>Songs </h2>
        <br/>
        <p>Try entering an artist to find their songs</p>
        <div>
            <div id="musicbox" class="control-group">
                <label for="songs">artistr</label>
                <input type="text" name="songs" id="songs" placeholder="Type an artist to their songs" />
            </div>
        </div>
        <br />
        <div>
            <button class='btn btn-success btn-large' onclick="Music('songs')">Find Songs</button>
        </div>
        <br />
        <div>
        </div>
    </div>
</body>
</html>

JS File

function Music(music) {
    var yourmusic = document.getElementById(music).value;
    var httpRequest = new XMLHttpRequest();
    httpRequest.onreadystatechange = function () {
        if (this.readyState === 4) {
            if(this.status === 200) {
                displayMusic(this.responseText);
            } else if (this.status === 404){
                displayMusic('{ "songs" : "none" }');
            } else {
                console.log("We have a problem: " + this.status);
            }
        } else {
        }
    };
    var url = " https://api.mixcloud.com/discover/funk/";
    httpRequest.open("GET", url, true);
    httpRequest.send();
}

function displayMusic(data){
    var music = JSON.parse(data);
    if(music.songs === "none") {
        document.getElementById("songs").className = "alert alert-warning";
        document.getElementById("songs").innerHTML = "The songs are" + music;
    } else {
        document.getElementById("songs").className = "alert alert-success";
        document.getElementById("songs").innerHTML ="there are no songs for this artist"
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了