Why isn't jQuery working on published site?
I'm using asp.net mvc2. I have created a project with good slideshows and menu. It works fine on local machine, but when I publish and view through the server, jQuery is not working.
He开发者_如何学Cre is how I'm including the script:
<script type="text/javascript" src="~/Resources/css/menu.js"> </script>
How can I get jQuery working?
You are using MVC 2 ..Right?
So Include script firl like shown below
<script src="<%= Url.Content("~/Scripts/jquery-1.4.4.min.js") %>" type="text/javascript"></script>
Please take a look at src part
For debugging (and probably getting a better answer) I recomend you to use one of the following options for your javascript:
- Developer Tools (F12) with IE9
- Firebug with Firefox / Chrome
If you have errors in your javascript (unreferenced libraries, or syntax errors) these tools will help you.
There are a number of things to check for:
- Make sure that you have included the jquery .js file in your solution
- Make sure you're referencing the jquery file relative and not absolute. Use
Url.Content("~/Path/ToFile.js")
In ASP.Net MVC2 you should reference your script files as below:
<script type="text/javascript" src="<%= Url.Content("~/Resources/css/menu.js")%>"></script>
You can also drag your script files into your Site.Master page and Visual Studio will create the reference for you.
Also as you can see from the other answers it is the convention in ASP.Net MVC to place any .js files in the scripts folder.
You need to add reference to Jquery libraries correct way using Url.Content,
<script src="<%=Url.Content("~/Scripts/jquery-1.5.1.min.js")%>" type="text/javascript"></script>
<script src="<%=Url.Content("~/Scripts/jquery-ui-1.8.11.js")%>" type="text/javascript"></script>
Check to make sure your deployed page can retrieve jQuery and your other javascripts on the deployed site. Chances are you forgot to deploy those files to your production server, or the URLs are wrong.
精彩评论