简体   繁体   English

JavaScript在本地运行,但在部署到Web服务器时无法运行

[英]JavaScript works locally but not when deployed to webserver

I'm deploying some code to a website and when I do the JavaScript does not run. 我正在将一些代码部署到网站上,但是当我运行JavaScript时,它无法运行。 I get the error: 我得到错误:

SCRIPT5007: The value of the property '$' is null or undefined, not a Function object. SCRIPT5007:属性“ $”的值为null或未定义,不是Function对象。

The code it is using is 它使用的代码是

@model MVCMasterDetail.DataAccess.cwwoLoadCurrentWorkOrderActualsResult[]

<script type="text/javascript">
  $(document).ready(function () {
    $(".grid-toggle").click(function () {
        $(this).closest("table").find("tbody").show();
    });
    $(".hide-rows").click(function () {
        $(this).closest("table").find("tbody").hide();
    });
});
</script>

@Html.Partial("MasterDetailMasterPartial")

And what calls uses it is: 调用使用它的是:

<td colspan="4"> Details<br/><a href="javascript: void(0)" class="grid-toggle">Show-     </a><a href="javascript: void(0)" class="hide-rows">Hide</a></td>

Any help is appreciated. 任何帮助表示赞赏。

Based off your comment in Ashley Ross's answer, it looks like your trying to add jQuery using a relative path. 根据您在Ashley Ross答案中的评论,看来您尝试使用相对路径添加jQuery。 it also looks like you're using MVC. 看起来您正在使用MVC。 In MVC, the way you want to reference a file in html is: 在MVC中,您要在html中引用文件的方式是:

<script src="@Url.Content("~/Scripts/jquery-1.7.1.js")"></script>

Also, it doesn't matter if your script tag goes in the head tag or not. 另外,脚本标签是否位于head标签中也没有关系。 The only difference it makes is loading. 唯一的区别是加载。 By putting it in the head tag, you're telling the browser to download the js file before it begins to load the body, which can be nice, but can also increase page load times. 通过将其放在head标签中,可以告诉浏览器在开始加载正文之前先下载js文件,这虽然不错,但也可能增加页面加载时间。 For faster page download, you actually want to put your script tags towards the bottom of your body tag, which defers downloading the js file until after the rest of the page has loaded. 为了更快地下载页面,您实际上希望将脚本标签放在body标签的底部,这将推迟下载js文件,直到页面其余部分加载完毕。 This results in faster page load times, but can cause some funky behaviors if you aren't anticipating it. 这样可以加快页面加载时间,但是如果您不期望这样做,可能会导致一些时髦的行为。

You need to include jQuery before any other scripts. 您需要在所有其他脚本之前包含jQuery。 It sounds like you have something like 听起来你有类似的东西

<script type="text/javascript" src="customScriptThatUsesjQuery.js"></script>
<script type="text/javascript" src="jquery-x.y.z.min.js"></script>

instead of 代替

<script type="text/javascript" src="jquery-x.y.z.min.js"></script>
<script type="text/javascript" src="customScriptThatUsesjQuery.js"></script>

Check that it appears in your HTML source before any other scripts that use it. 检查它是否出现在您的HTML源代码中,然后再使用它的其他脚本。

您必须在<head>添加对jquery lib的引用

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

暂无
暂无

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

相关问题 ASPX在本地工作,但不能在网络服务器上工作 - ASPX works locally but not on webserver Database First DBContext在本地工作,但在部署时无法工作 - Database First DBContext works locally but not when deployed 简单的WebClient在本地工作,但在部署到Azure时无法工作 - Simple WebClient works locally, but not when deployed to Azure 我的asmx Web服务在本地工作,但在远程IIS 7上部署时不工作 - My asmx webservice works locally but not when deployed on remote IIS 7 具有约束的属性路由在本地工作,但在部署时会失败 - Attribute Route with constraint works locally but fails when deployed ASP.NET Core(HttpSys)路由在本地工作,但在部署时不工作 - ASP.NET Core (HttpSys) Routing works locally but not when deployed 将映像上传到Azure Blob存储-本地工作,部署后失败 - Uplod images to azure blob storage - Works locally, fails when deployed Google Map Direction Api在本地工作正常,但在服务器上部署后无法正常工作 - Google Map Direction Api Works Fine Locally but does not work properly when deployed on Server C# Azure ServiceBus / Azure SQL - 在本地工作,部署到 Azure 时似乎不起作用 - C# Azure ServiceBus / Azure SQL - works locally, does not seem to work when deployed to Azure Angular 8 - 路由在本地工作,但在生产环境中部署时,路由不起作用 - .NET 核心 C# 后端 - Angular 8 - routing works locally, but when deployed on Production, routes don't work - .NET Core C# backend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM