user1027620
user1027620

Reputation: 2785

Loading External .js file that requires jQuery

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 () { });

Upvotes: 0

Views: 632

Answers (2)

Cory Danielson
Cory Danielson

Reputation: 14501

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>

Upvotes: 1

SLaks
SLaks

Reputation: 887365

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

Upvotes: 0

Related Questions