简体   繁体   中英

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

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>

您应该在ScriptManagerProxy中引用外部文件,以确保它们以正确的顺序执行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM