找不到Javascript文件 [英] Javascript File Not Found

查看:139
本文介绍了找不到Javascript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将javascript文件链接到我的网页时,我收到一个随机错误。自从我完成任何Web开发以来已经有一段时间了。但是,我检查了旧代码,方法是相同的。我试图第一次使用jquery,我不确定这是否会影响结果。

I am getting a random error when I attempt to link a javascript file to my web page. It has been a while since I have done any web development. However, I have checked old code and the methods are identical. I am attempting to use jquery for the first time and am not sure if that is effecting the results.

这是HTML标题:

<!DOCTYPE html >
<html>
<head>
<link rel="stylesheet" href="Styles/layoutStyles.css" type="text/css">

<meta content="text/html; charset=UTF-8">

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> 
<script src="CommonMethods.js" type="text/javascript"></script>

<title>Insert title here</title>
</head> 

CommonMethods.js文件是我尝试使用的文件。它最初位于较低的目录中,然后是HTML文件。但是,为了测试目的,我将它移到同一目录。

The "CommonMethods.js" file is the file I am attempting to use. It was initially in a lower directory then the HTML file. However, I moved it to the same directory for testing purposes.

这是我得到的错误:

GET file:///D:/Users/Thomas.Thomas-TOWER/Dropbox/Workspaces/Eclipse_Web_Develop…nder/WebContent/%C3%A2%E2%82%AC%C2%9DCommonMethods.js%C3%A2%E2%82%AC%C2%9D net::ERR_FILE_NOT_FOUND 

I我不确定%C3%A2%...等等。符号来自。我几乎想知道我定义字符集的方式是否有问题。

I am not sure where the %C3%A2%...ect. symbols came from. I am almost wondering if there is something wrong with the way I defined the charset.

有什么建议吗?

我还应该提到我在这个项目中使用Eclipse。

I should also mention I am using Eclipse for this project.

推荐答案

<你正在使用智能引号。在真正的IDE中打开文件 Netbeans ,Eclipse, ShiftEdit ,Coda等。)并替换它们。

You're using smart quotes. Open the file in a real IDE (Netbeans, Eclipse, ShiftEdit, Coda, etc.) and replace them.

这也是一般的好习惯root脚本/样式网址。 (IE /CommonMethods.js

Also it's generally good practice to "root" script/style urls. (I.E. "/CommonMethods.js")

在任何较大的项目中,相对网址可能会有问题,因为您并不总是在根网站上。

On any larger project relative urls can be problematic as you're not always at the root.

另一个提示是第三方脚本的无协议URL(IE //ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js )

Another tip would be protocol-less URLs for 3rd party scripts (I.E. //ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js)

所有现代浏览器都支持这一点,它可以避免因在安全页面上运行的不安全内容而头疼

All modern browsers support this and it saves you headache from insecure content being run on a secure page

此外,在脚本标签上不再需要HTML5 type =text / javascript。

Also as of HTML5 type="text/javascript" is not longer required on script tags.

此外,如果您使用的是Visual Studio,请记住将Copy设置为Output Directory复制始终或复制如果较新。

Also if you are using Visual Studio, Please remember to set Copy to Output Directory to Either Copy Always or Copy if Newer.

这篇关于找不到Javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆