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
 |  Show 1 more ment

2 Answers 2

Reset to default 1

I 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