0

So there I am trying to load an external .js file which in return loads other pages using $.ajax and jQuery Templates. Everything was working when my code was all in a single .aspx page. But after distributing everything to separate clean files I am having this error:

Default.aspx

<asp:ScriptManagerProxy ID="ScriptManagerProxy" runat="server">
    <Scripts>
        <asp:ScriptReference Path="~/Scripts/jquery-1.7.min.js" />
        <asp:ScriptReference Path="~/Scripts/jQuery.tmpl.min.js" />
        <asp:ScriptReference Path="~/Pages/Templates/Stream/Stream.js" />
    </Scripts>
</asp:ScriptManagerProxy>

Stream.js

GetStream();

 function GetStream() {
        alert('ok'); 
        $.ajax({ /* It reaches this line */
        type: 'POST',

But returns the following.

$ is undefined

Please note that I have added the Stream.js file seperately without using the ScriptManagerProxy below the jquery-1.7 file. And still got the same thing. Ideas?

I forgot to mention that the content of Stream.js is wrapped in:

$(document).ready(function () { });
1
  • "$ is undefined error" is happening becouse your jquery code run before jquert included to your site Commented Nov 17, 2011 at 19:48

2 Answers 2

1

What is the benefit of using the script manager for this? It's just going to format/output HTML tags.. Why not use HTML instead.

<script language="javascript" src="/Scripts/jquery-1.7.min.js"></script>
<script language="javascript" src="/Scripts/jQuery.tmpl.min.js"></script>
<script language="javascript" src="/Pages/Templates/Stream/Stream.js"></script>
Sign up to request clarification or add additional context in comments.

3 Comments

I sort of need the provided function pageLoad() that also executes and rebinds jquery selectors on partial postbacks.
Yes, but the Stream.js file is required on this page only and I'm trying not to load it on all my pages.
At the top of this partial, just add the script tag for Steam.js. You can embed <script> tags anywhere that's convenient, not just the <head>
0

You should reference the external file in the ScriptManagerProxy to make sure they're executed in the correct order.

2 Comments

Hey SLaks thanks for the answer. I am referencing Stream.js in the ScriptManagerProxy Script References.
Well the undefined error and please see this jeffreyramia.com/firebug.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.