获取语​​法错误:部署时json输入意外结束

时间:2020-10-23 03:47:35

标签: javascript html json api syntax-error

我试图获取用户的ip地址,该地址在本地运行代码时可以正常运行。但是,当我在netlify中部署它时,就会出现问题。 代码示例:
HTML:-

<body>
    <h1>Ip Address Tracker</h1>
    <div class="my-ip">
        <button class="myIp">Check My Ip</button>
    </div>
    <div class="input-ip">
        <input type="text" placeholder="Search for any Ip" />
        <button>submit</button> 
    </div>
</body>

JavaScript:-

let myIpBtn = document.querySelector('.myIp')
myIpBtn.addEventListener('click', () => {
    fetch('https://api.ipify.org/?format=json')
        .then(results => results.json())
        .then(data => {
            console.log(data.ip)
            getLocation(data.ip)
        })
        .catch(e => {
            console.log(e.message)
        })
})

我收到语法错误:.then(results => results.json())行的Json Input的未扩展结尾
源代码:https://github.com/Abir10101/test.git 应用:https://abir10101.github.io/test/index.html

0 个答案:

没有答案