正如标题所说,我试图在我的网站上创建一个YouTube搜索功能。这是我到目前为止所得到的:
$(document).ready(function() {
$("#searchbutton").click(function (e) {
e.preventDefault();
var searchInput = $("#search");
$.get(
"https://www.googleapis.com/youtube/v3/search",
{
part: 'snippet',
maxResults: 1,
q: searchInput,
key: 'my_key'
}, function (data) {
console.log(data.items.id.videoId);
}
);
});
});
当我按下#searchbutton时,它会将输入放入' searchInput'然后它将searchInput放入' q'。这是我的html代码:
<form>
<input type="text" id="search"/>
<button type="submit" id="searchbutton">Find</button>
</form>
现在我只是想在控制台中制作videoId输出。问题是,当我点击搜索按钮时,我的整个网站都没有响应。我当时仍然可以使用其他网站,但我的网站不再响应了。我知道变量&#39; searchInput&#39;是问题所在,因为无论何时我输入像“狗”这样的东西。在&#39; q&#39;,它只会给我一个关于狗视频的视频。有谁知道为什么&#39; searchInput&#39;让我的网站没有回应?或者有没有更好的方法来完成整个YouTube搜索?