为什么我的 .js 文件会出现 404 错误?
我正在使用 Wordpress,并且链接了一些砌体 jQuery 库文件,当尝试访问 .js 文件时,它会出现 404。但是,我的自定义函数是可见的,jQuery .js 文件也是如此。为什么会变成 404?我花了 1 个小时试图找出为什么我的函数不起作用,结果发现文件没有正确加载。
这就是我链接到 jQuery 文件的方式:
<script language="javascript" type="text/javascript" src="http://domain.com/js/custom.js"></script>
<script language="javascript" type="text/javascript" src="http://domain.com/js/jquery.eachdelay-0.0.1.js"></script>
<script language="javascript" type="text/javascript" src="http://domain.com/js/jquery.masonry.min.js"></script>
出于某种原因,custom.js
工作正常,但其他的则不行。我已经正确上传了。当我尝试访问浏览器中的其他文件时,它显示“找不到页面”。
I'm using Wordpress, and I linked some masonry jQuery library files and when trying to visit the .js file, it goes to a 404. However, my custom functions are viewable and so is the jQuery .js file. Why might it be going to a 404? I spent 1 hour trying to figure out why my function wasn't working and it turns out the file wasn't being loaded properly.
This is how I am linking to the jQuery files:
<script language="javascript" type="text/javascript" src="http://domain.com/js/custom.js"></script>
<script language="javascript" type="text/javascript" src="http://domain.com/js/jquery.eachdelay-0.0.1.js"></script>
<script language="javascript" type="text/javascript" src="http://domain.com/js/jquery.masonry.min.js"></script>
For some reason, custom.js
works fine, but not the others. I have it uploaded properly. It says "Page not found" when I try to visit the other files in the browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
结论是:
我创建了另一个文件并删除了旧文件,然后用相同的名称重命名了新文件,但它不起作用。所以,我最终创建了一个文件并将其命名为原始默认值以外的名称,然后将 JS 内容粘贴到我制作的新文件和中提琴中!
我认为这是一个缓存问题,我不知道如何解决它以及为什么会发生,但这是我的解决方案。另外,人们不应该如此仓促地认为 404 意味着我不知道如何上传文件并且我将其上传到了错误的目录。
Here's the conclusion:
I created another file and deleted the old one then renamed the new one with the same name and it didn't work. So, I just ended up creating a file and naming it something other than the original default and then pasted the JS contents in to the new file I made and viola!
I think its a caching problem, I don't know how to fix it and why it happened but this was my solution. Also, people should not be so hasty to assume that the 404 means that I do not know how to upload a file and that I uploaded it to the wrong directory.
尝试对 js 文件使用绝对 URL 路径。
try using an absolute URL path for the js file.