admin管理员组文章数量:1405546
I have tried running a simple html file which includes a jquery.js file with a jquery click() alert, when I manually open the html file in a browser the jquery/javascript works fine.
However if I host this html (or any aspx) file in IIS 7.5 everything else works including CSS and html however the jquery javascript functions from the .js do not work. I have a clean install of ASP.NET, IIS 7.5 and Visual Studio 2010 but no luck.
I looked in the applicationHost.config file and .js files seem to be there and enabled. I am running the application pool for the IIS website in Integrated mode 4.0. The weird thing is that Visual Studios built in Cassini web dev server also has the same problem and won't server .js files. This is what is in my web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<pilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<urlCompression doStaticCompression="true" />
</system.webServer>
</configuration>
Any ideas? Here is the html, I've tried it with the google cdn jquery js too:
<html>
<head>
<script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
</body>
</html>
I have tried running a simple html file which includes a jquery.js file with a jquery click() alert, when I manually open the html file in a browser the jquery/javascript works fine.
However if I host this html (or any aspx) file in IIS 7.5 everything else works including CSS and html however the jquery javascript functions from the .js do not work. I have a clean install of ASP.NET, IIS 7.5 and Visual Studio 2010 but no luck.
I looked in the applicationHost.config file and .js files seem to be there and enabled. I am running the application pool for the IIS website in Integrated mode 4.0. The weird thing is that Visual Studios built in Cassini web dev server also has the same problem and won't server .js files. This is what is in my web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<pilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<urlCompression doStaticCompression="true" />
</system.webServer>
</configuration>
Any ideas? Here is the html, I've tried it with the google cdn jquery js too:
<html>
<head>
<script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
</body>
</html>
Share
Improve this question
edited Feb 17, 2012 at 18:58
User101
asked Feb 16, 2012 at 22:03
User101User101
8583 gold badges12 silver badges33 bronze badges
6
- Did you checke that the javascript is not disabled in the browser?! – gdoron Commented Feb 16, 2012 at 22:06
- Could you please provide html of your page? – Evgeny Lukashevich Commented Feb 16, 2012 at 22:12
- Hi @Eugene and gdoron the html and javascript reference to jquery works fine in all browsers when I drag it manually into the browsers. However its only when its hosted by IIS/VS web server that it won't serve it. I even tried using the google CDN jquery but to no luck. So I don't think there is a problem with the code, its certainly setup either of asp or my web.config. – User101 Commented Feb 17, 2012 at 9:17
- @Eugene added html to original post – User101 Commented Feb 17, 2012 at 18:58
- Any error messages in the console? There must be some if jQuery is not being included – Pekka Commented Feb 17, 2012 at 19:03
2 Answers
Reset to default 1I reinstalled IIS and all was well, though that required a restart which maybe I hadnt done the first time around!
I'll guess that your path is resolving to different location, if you are using WebForms it's better to specify path like this:
<script type="text/javascript" src="<%=Page.ResolveUrl("~/Scripts/jquery-1.7.1.min.js")%>">
For ASP.NET MVC you can use:
<script type="text/javascript" src="<%=Url.Content("~/Scripts/jquery-1.7.1.min.js")%>">
本文标签: jqueryJavascript js files not working in IIS 75Stack Overflow
版权声明:本文标题:jquery - Javascript .js files not working in IIS 7.5 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744332285a2601021.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论