Youtube API在DW中工作但在JSFiddle中有POST错误

时间:2014-07-12 03:21:59

标签: javascript youtube youtube-api youtube-javascript-api youtube-data-api

我已经在使用Youtube API几天了,这只是我的第二个“项目”。我刚刚完成了flickr api,所以我想我会给你一个镜头。

代码适用于Dreamweaver,但不适用于jsfiddle。我认为它与提交有关,但我在过去的几个小时里已经骗了它,但必须遗漏一些东西。

非常感谢您的任何意见!

http://jsfiddle.net/amithere/7uLRU/2/

<script src="https://apis.google.com/js/client.js?onload=loaded" type="text/javascript"></script>
    </head>
    <body>

        <body>
    <h1 id="header"> Search YouTube </h1>
    <section id="center">
        <form id="theform">
            <p><input type="text" name="term" id="term" value="dog"></p>
            <p><input type="submit" id="submit" value="Search"></p>
        </form>
    </section>
    <div id='here'> Here: </div>
    <pre id="response"></pre>
    </body>


var apiKey = 'myKey';

function showResponse(response) {
    var responseString = JSON.stringify(response, '', 2);
    document.getElementById('response').innerHTML += responseString;
}

function loaded(event) {
    gapi.client.load('youtube', 'v3', gapi.client.setApiKey(apiKey));
}   


$("#theform").on("submit", function(e) {
    e.preventDefault();
    var request = gapi.client.youtube.search.list({
        part: 'snippet',
        q: document.getElementById('term').value,
        maxResults: 1
    });
});

    request.execute(onSearchResponse);
}

function onSearchResponse(response) {
    showResponse(response);
}

0 个答案:

没有答案
相关问题