Bootstrap - jQuery not defined

I created an ASP.NET application and want to validate the form using jQuery.

When the page is refreshed, the chrome console displays the following error:

Unprepared ReferenceError: $ undefined

This is my homepage code:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <title></title>

    <link href="Styles/bootstrap.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src='<% ResolveUrl ("~/scripts/jquery-1.11.3.js"); %>'></script>
    <script src="Scripts/validations.js" type="text/javascript"></script>
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form runat="server" class="form-inline" role="form">
        <div class="container">
            <div class="jumbotron">    
                <h1>Statement Generator</h1>
                <p>This application is used to generate PDFs</p>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
                </div>
            </div>
            <div class="clear">
            </div>
        </div>
        <div class="footer">

        </div>
    </form>
    <script type="text/javascript" src='<% ResolveUrl ("~/scripts/jquery-1.11.3.js"); %>'></script>
    <script type="text/javascript" src='<% ResolveUrl ("~/scripts/bootstrap.min.js"); %>'></script>

</body>
</html>

This is my code in validations.js:

$(function () {
    alert();
});

Am I missing something?

+4
source share
2 answers

You need to remove the last jquery declaration, it is already declared inside the tag <head>. Can you first try to delete the last instance, and then try, another thing you can do is directly change it to:

<script type="text/javascript" src="~/scripts/jquery.js">

Just to find out if the problem is ResolveUrl().

, , ResolveUrl, ResolveUrl , UserControls images.

msdn: https://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveurl.aspx

+4

<script type="text/javascript" src='<% ResolveUrl ("~/scripts/jquery-1.11.3.js"); %>'></script>

<script type="text/javascript" src='<%= ResolveUrl("~/scripts/jquery-1.11.3.js") %>'></script>

, <%= %>, Response.Write, <% %> - ResolveUrl . https://support.microsoft.com/en-us/kb/976112 , !

+1

Source: https://habr.com/ru/post/1627201/


All Articles