1

我正在使用 git api 进行存储库搜索。问题是当我使用实时服务器时,搜索工作正常。但是当我上传到 github 页面时,我收到以下错误:

来自控制台的错误

我的代码是:

<header class="container">

      <nav class="navbar navbar-expand-lg navbar-light bg-secondary">
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
      
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
              <a class="nav-link" href="#">perfil</a>
            </li>

            <li class="nav-item">
              <a class="nav-link" href="#">Projetos</a>
            </li>

            <li class="nav-item">
              <a class="nav-link" href="#">experiência</a>
            </li>
            
            <li class="nav-item active">
              <a class="nav-link" href="#">repositorio github</a>
            </li>
            
            <li class="nav-item">
              <a class="nav-link" href="#">conteudo</a>
            </li>
          </ul>
          <form class="form-inline my-2 my-lg-0">
            <input class="form-control mr-sm-2" type="search" id="searchInput" placeholder="Search repository" aria-label="Search">
            <button class="btn btn-success my-2 my-sm-0" id="btnSearch">Search</button>
          </form>
        </div>
      </nav>

    </header>

和 javascript:

import { Octokit } from "https://cdn.skypack.dev/@octokit/core";

let HttpRequest = new XMLHttpRequest()

btnSearch.addEventListener("click", async function(e){
e.preventDefault();

const octokit = new Octokit({ auth: `myToken` })

let query = document.getElementById("searchInput").value 
//console.log(query)

const response1 = await octokit.request('GET /search/repositories', {
    q: query
});

console.log(response1)

let pesquisa = "";
for(let i = 0; i < response1.data.items.length; i++){
    pesquisa += `<a href="${response1.data.items[i].html_url}">${response1.data.items[i].full_name}</a><br>
                <p>${response1.data.items[i].description}</p><br><br>`
}

document.getElementById("pesquisa").innerHTML = pesquisa;

})

为什么这适用于实时服务器而不是 github 页面中的工作人员?怎么修?

4

0 回答 0