views:

251

answers:

2

There has to be something utterly simple I'm overlooking here, but for the life of me I can't get a JavaScript file to include properly from my master page. My declaration in the <head> element looks normal enough:

<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" src="/_private/scripts/jquery-1.2.6.min.js"></script>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>

But when the page loads, the js file is simply missing. Instead, what we get in Firebug when trying to expand that script element is just the page's HTML all over again.

I've included js files like this successfully countless times before and as far as I can tell, I've done it the exact same way again. It's hardly rocket science, so I must be overlooking something blindingly obvious but damned if I can figure out what it is.

In desparation, I turn to you. Any ideas?

One final point as well: viewing the source of the page shows a very unlikely form action. Even when browsing directly to the default page, there is a ReturnUrl being included on the form action and that ReturnUrl is the location of the missing script:

<form name="aspnetForm" method="post" action="default.aspx?ReturnUrl=%2f_private%2fscripts%2fjquery-1.2.6.min.js" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
+1  A: 

If you are running this inside of Visual Studio, chances are the link won't work. By default, VS serves up sites as something like http://localhost:3456/projectname/... so /_private won't actualy be at the root.

You can change this in the properties on the project/solution, or use some other approaches to rewrite the script path dynamically.

As to the second bit about the form action, is there any chance your js file is in a protected directory? Looks like a login/return path url.

seanb
GAA!!!I knew it would be something blindingly obvious. Well done that man - I'd set authorization on that directory by mistake. Thank you!
Phil.Wheeler
A: 

That form URL is truly bizarre, but have you tried leading your path with the "~/" root construct?

annakata