Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌图书API有问题吗_Javascript_Request_Fetch_Fetch Api_Google Books Api - Fatal编程技术网

Javascript 谷歌图书API有问题吗

Javascript 谷歌图书API有问题吗,javascript,request,fetch,fetch-api,google-books-api,Javascript,Request,Fetch,Fetch Api,Google Books Api,我想创建一个应用程序,用户可以使用谷歌图书API搜索图书。当前正在尝试显示搜索操作的结果,但我的请求出现问题(API密钥已启用)。如果你能帮助我,我将非常感激。这是我迄今为止创建的函数: //requests.js file export const loadSearchBooks = (searchTerm = '') => { return fetch(`https://www.googleapis.com/books/v1/volumes?q=${searchTerm}&am

我想创建一个应用程序,用户可以使用谷歌图书API搜索图书。当前正在尝试显示搜索操作的结果,但我的请求出现问题(API密钥已启用)。如果你能帮助我,我将非常感激。这是我迄今为止创建的函数:

//requests.js file
export const loadSearchBooks = (searchTerm = '') => {
    return fetch(`https://www.googleapis.com/books/v1/volumes?q=${searchTerm}&key=${API_KEY}`)
        .then((response) => response.json());
};

//render-pages.js file
export const displaySearch = (term) => {
  loadSearchBooks(term).then((res) => MAIN.innerHTML = toSearchView(res.data));
};

//index.js file main
document.addEventListener('DOMContentLoaded', () => {
    document.addEventListener('click', (e) => {
      if (e.target.classList.contains('nav-link')) {
        loadPage(e.target.getAttribute('data-page'));
        e.preventDefault();
      }
      const currentSearch = document.getElementById('search-term').value;
      if (e.target.id === 'search-btn') {
      displaySearch(currentSearch);
    }
    });

    loadPage('home');
});