I have a problem with my a javascript file im refrencing to a master page.
this is the code:
<head runat="server">
<type="text/javascript" src="../Jquery1.6_vsdoc/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
the jquery files work fine, but the main.js not.
when i open the aspex file on the web browser and do view source, and try to see the code on the main.js file iis show this message:
HTTP Error 404.0 - Not Found The resource you are looking for has been
removed, had its name changed, or is temporarily unavailable.
what do i do worng here?
some info on the file (if it will help):
he is the same directory of the master page
he is ony refreced in 1 master page.
im using visual studio 2012
(sorry for my english)
Use Page.ResolveUrl() in Master Page scenarios
so your reference should look like this
<type="text/javascript" src="<%= Page.ResolveUrl("~/Jquery1.6_vsdoc/jquery-1.7.1.min.js") %>"></script>
<script type="text/javascript" src="<%= Page.ResolveUrl("~/main.js") %>"></script>
This will ensure that the page is mapped correctly as the Child Page may not be in the same location as the Master Page
Related
I am having a problem in the location of my javascript, the location is right, but when I run it in my visual web developer 2010 express, the location can not be found, I don't know the reason why...
here is the location of my javascript:
<script src="Style/javascript/jquery-1.7.1.js" type="text/javascript"></script>
here is the error:
**Server Error in '/Maitenance' Application.**
**The resource cannot be found.**
**Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.**
**Requested URL: /Maitenance/Maintenance/Style/javascript/jquery-1.7.1.js**
Use this... It will work
<script src="<%=Page.ResolveUrl("~")%>Style/javascript/jquery-1.7.1.js" type="text/javascript"</script>
I guess you are using a master page and your .aspx page is put in another directory. The file path you included in master page is relative to the .aspx file. It works OK when your page in the same directory with the master page.
You can include your js file using ResolveUrl:
<script src="<%=ResolveUrl("~/js/jquery.js")%>" type="text/javascript"></script>
or you can include your script in the code behind of master page:
ClientScript.RegisterClientScriptInclude("jquery", ResolveClientUrl("~/js/jquery.js"));
I'm using webform asp.net and C#. I linked the master page with javascript file like this
<script type="text/javascript" src="javascript/main.js"></script>
but when I'm going to inner pages inside folders.. I can't access the JavaScript file.. (404 error).I tried to solve the problem by using ResolveClientUrl but it's not work!
What's the problem?
but when I'm going to inner pages inside folders.. I can't access the JavaScript file
Since the page you're accessing is at a different level than your master page, you want to make the script path relative to the root of your application
<script type="text/javascript" src="/javascript/main.js"></script>
EDIT if that's not working, then I would keep the script tag as it is above, run it in Chrome with the developer tools / network tab open, and look at the exact address that shows up for the failed request. Then look closely at your application and see what's different / wrong.
You can do:
<script type="text/javascript" src="<%=Page.ResolveClientUrl("~/javascript/main.js") %>" />
Allows you to use ASP.NETs ~. If this doesn't work then the file doesn't exist in that directory.
In Web Application Solution, I have a master page that is located in the root folder. I also have web forms that use this master page and are located in a folder in the root folder.
master page ----located----> root folder
web forms--------located----> root folder/forms
I have JavaScript that cannot run in the web form because this code can't access the source file in the scripts folder.
I used the following:
<script type="text/javascript" src="<%= Page.ResolveClientUrl("~/Scripts/stmenu.js") %>"></script>
However, it results in this error:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
How can I insert the JavaScript, that is located in a separate folder, into the master page?
Please add runat="server" to the head tag like this
<head runat="server">
Also please use Page.ResolveUrl like this
<script type="text/javascript" src="<%= Page.ResolveUrl("~/Scripts/stmenu.js") %>">
</script>
Add another asp:contentplaceholder in the <head> section of the Master Page where the Webforms can place their Javascript references and code.
Im attempting to utilize some custom script and css files within an asp page. In Visual Studio 2010 I am not getting any warnings or errors as to the status of these files, but when I attempt to run the page, and I open the javascript console I get the error:
Failed to load resource: the server responded with a status of 404 (Not Found)
Here's how I am attempting to load the files in my ascx file:
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/jquery.scripts.js"></script>
<script type="text/javascript" src="scripts/jquery.alerts.js"></script>
<link href="styles/jquery.alerts.css" rel="stylesheet"/>
Anyone know whats going on here, why the browser can't locate the files but visual studio can?
This happens when the location of the .aspx file is different to the location of the user control (ascx).
When the user control is rendered in the browser it will actually have the location of the .aspx and tries to make the reference from that point. Whereas in VS, it will try to make the reference to the file from the .ascx location.
Therefore, try referencing the files as if you were making the references from the .aspx file location. It shouldn't give you any error when rendering that page.
I've upvoted aleafonso's answer since he's correct. Now, to solve this issue, you can use the ResolveClientUrl method.
Something like this:
<script type="text/javascript" src='<%=ResolveClientUrl("scripts/jquery.js"%>'></script>
I installed SpringSource Tool Suite 2.8.0.
I'm trying to include a JS file in a JSP, using the Spring MVC template as a starting point.
My JSP looks like this:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page session="false" %>
<html>
<head>
<title>Home</title>
<script type="text/javascript" src="/a.js"></script>
</head>
<body>
Hello world!
</body>
</html>
a.js is under src\main\resources and looks like this:
window.alert("A");
The result is that "Hello world!" gets printed without the alert :-(
I tried putting the JS file in different places, changing the src to be with/without "/", and even adding a servlet-mapping in web.xml to use "default" servlet for "*.js".
Nothing seems to work.
What am I doing wrong?
is the js file getting included in your .war file? I usually put my js and css in src/main/webapp. something like src/main/webapp/js and src/main/webapp/css.
Secondly, you can reference it appropriately using c:url which will take care of putting the app context on there and stuff.
<script type="text/javascript" src="<c:url value="/a.js" />" />
You can use firebug or chrome's developer tools to see if you are getting a 404 for a.js and see what path it is actually requesting.
I advise placing those js files under webapp folder. (I usually put them under webapp/resources/js)
And to make this path accessible, I use the mvc:resources tag:
This tag allows static resource requests following a particular URL
pattern to be served by a ResourceHttpRequestHandler from any of a
list of Resource locations. This provides a convenient way to serve
static resources from locations other than the web application root,
including locations on the classpath. The cache-period property may be
used to set far future expiration headers (1 year is the
recommendation of optimization tools such as Page Speed and YSlow) so
that they will be more efficiently utilized by the client. The handler
also properly evaluates the Last-Modified header (if present) so that
a 304 status code will be returned as appropriate, avoiding
unnecessary overhead for resources that are already cached by the
client. For example, to serve resource requests with a URL pattern of
/resources/** from a public-resources directory within the web
application root, the tag would be used as follows:
<mvc:resources mapping="/resources/**" location="/public-resources/"/>
Source: Spring Reference