繁体   English   中英

在看似没有改变之后,正在工作的 function 现在正在加载资源失败:net::ERR_CONNECTION_REFUSED

[英]After changing seemingly nothing, a function that was working is now getting Failed to load resource: net::ERR_CONNECTION_REFUSED

我的网站上有一个 function ,每次单击它都会更改图像。 突然这停止工作,并且在控制台中加载页面时出现此错误:

Failed to load resource: net::ERR_CONNECTION_REFUSED

还有一次点击图片

localhost:3002/pics/gymshark.png:1 GET http://localhost:3002/pics/gymshark.png net::ERR_CONNECTION_REFUSED

我将我的提交恢复为我确定可以正常工作的旧提交,但我仍然收到此错误。 知道会发生什么变化吗? 这个 function 与我的本地浏览器同步服务器以及我的 github 页面版本的站点一起使用。

下面看看html和js操作function

html

<div id='gsk' class="col-lg-4 col-md-6 ">
  <img src="pics/gymshark.png" class='clothes' id='gsk-img' onclick="changeGymShark()" >
  <div class="title">The Gym Shark</div>
  <div class='price'>$45</div>
  <audio class="gymshark" src="music/backroad.mp3" controls></audio>
</div>

js

function changeGymShark(){
    console.log(document.getElementById("gsk-img").src)
    if (document.getElementById("gsk-img").src == "http://localhost:3002/pics/gymshark.png") {
        document.getElementById("gsk-img").src = "http://localhost:3002/pics/gymshark-back.png"
    }
    else {
        document.getElementById("gsk-img").src = "http://localhost:3002/pics/gymshark.png"
    }
}

感谢您的任何帮助。

它还在本地为您工作吗?

看起来问题出在您的getGymShark() function 上,因为您在 github 上的站点仍在尝试访问localhost域,这在托管站点上不起作用。 尝试编辑它以使用服务器上图像的相对路径:

function changeGymShark(){
    console.log(document.getElementById("gsk-img").src)
    if (document.getElementById("gsk-img").src == "/domestic-accessories/pics/gymshark.png") {
        document.getElementById("gsk-img").src = "/domestic-accessories/pics/gymshark-back.png"
    }
    else {
        document.getElementById("gsk-img").src = "/domestic-accessories/pics/gymshark.png"
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM