Jquery code $ accuses it is not defined [closed]

-3

Good afternoon. I was cleaning up the code, and when I see it in the Chrome console, it accuses $ is not set.

jQuery code:

$(document).ready(function () {
    $('form').attr("autocomplete", "off");
});

In the first line of the code it shows that it is not defined.

HTML code:

<script src="~/Scripts/LoginAccount.js"></script>
<div id="fb-root"></div>
<section class="login-page">
    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
            <h2 class="">Faça seu login</h2>
            <h3 class="">Preencha o formulário com seu usuário e senha</h3>
            @if (ViewBag.SrcUrl == "landingPageGuiaComercial")
            {
                var returnUrl = "/usuario/hotsites";
                using (Html.BeginForm(new { returnUrl }))
                {
                    @Html.ValidationSummary(true, "Tentativa mal sucedida. Por favor corrija os erros e tente novamente.", new { @class = "alert alert-danger" })

                    <div class="form-group">
                        @Html.TextBoxFor(m => m.UserName, new { maxlength = "30", placeholder = "Usuário", autocomplete = "off", @class = "form-control inputusuario" })
                    </div>
                    <div class="form-group">
                        @Html.PasswordFor(m => m.Password, new { maxlength = "30", placeholder = "Senha", autocomplete = "off", @class = "form-control inputsenha" })
                    </div>
                    <div class="checkbox">
                        <label>
                            @Html.CheckBoxFor(m => m.RememberMe) Lembre-me
                        </label>
                    </div>

                    <input type="submit" value="Entrar" class="btn btn-success btnentrar" />
                    @Html.ActionLink("Esqueci minha senha", "ForgotPassword", null, new { @class = "forgot btn btn-warning btnsenha" })
                    <a href="/usuario/cadastrar?srcUrl=landingPageGuiaComercial" class="register btn btn-primary btnnovo">Novo Cadastro</a>
                }
            }
            else
            {
                using (Html.BeginForm(new { ViewBag.ReturnUrl }))
                {
                    @Html.ValidationSummary(true, "Tentativa mal sucedida. Por favor corrija os erros e tente novamente.", new { @class = "alert alert-danger" })

                    <div class="form-group">
                        @Html.TextBoxFor(m => m.UserName, new { maxlength = "30", placeholder = "Usuário", autocomplete = "off", @class = "form-control inputusuario" })
                    </div>
                    <div class="form-group">
                        @Html.PasswordFor(m => m.Password, new { maxlength = "30", placeholder = "Senha", autocomplete = "off", @class = "form-control inputsenha" })
                    </div>
                    <div class="form-group">
                        <label class="radio-inline">
                            @Html.CheckBoxFor(m => m.RememberMe) Lembre-me
                        </label>
                        <label class="checkbox-inline">
                            @Html.RadioButtonFor(m => m.EditAccount, true, new { @checked = "checked" }) Editar meu cadastro
                        </label>
                        <label class="checkbox-inline margin-left">
                            @Html.RadioButtonFor(m => m.EditAccount, false, new { @class = "margin-left" }) Continuar navegando
                        </label>
                    </div>
                    <div class="form-group center">
                        <input type="submit" value="Entrar" class="btn btn-success btnentrar" />
                        @Html.ActionLink("Esqueci minha senha", "ForgotPassword", null, new { @class = "forgot btn btn-warning btnsenha" })
                        @Html.ActionLink("Novo Cadastro", "Register", null, new { @class = "register btn btn-primary btnnovo" })
                    </div>
                }
            }
            @if (ViewBag.SrcUrl == "landingPageGuiaComercial")
            {
                <div class="videoLandingPageGuiaComercial">
                    <a href="http://www.abcdoabc.com.br/Embed/23" title="Apresentação do Hotsite" class="shadowbox600450">
                        <strong>VEJA O VÍDEO DE APRESENTAÇÃO DO HOTSITE</strong>
                        <img src="@Url.Content("~/Images/landingpage/apresentacao-video.jpg")" alt="Apresentação do Hotsite" class="img-responsive" />
                    </a>
                </div>
            }

        </div>

        @if (ViewBag.SrcUrl == "landingPageGuiaComercial")
        {
            <div class="adLandingPageGuiaComercial">
                <img src="@Url.Content("~/Images/landingpage/landingpage-publicidade-login.jpg")" alt="Entrar ou Cadastre-se" class="img-responsive" />
                <h3>ENTRE EM CONTATO</h3>

                <p>
                    <strong>
                        Aqui você poderá solicitar a criação de seu Hotsite pela agência!
                    </strong><br />
                    Envie um e-mail que entraremos em contato ou ligue para o número abaixo
                </p>

                @using (Ajax.BeginForm("EnviarEmailCriarHotsite", "Home", null, null, new { @class = "form", role = "form", style = "width:550px" }))
                {
                    <div class="form-group">
                        @Html.TextBox("Nome", null, new { placeholder = "Nome", @class = "form-control" })
                    </div>
                    <div class="form-group">
                        @Html.TextBox("Email", null, new { placeholder = "E-mail", @class = "form-control" })
                    </div>
                    <div class="form-group">
                        @Html.TextBox("Telefone", null, new { placeholder = "Telefone", @class = "form-control" })
                    </div>
                    <div class="form-group">
                        @Html.TextArea("Mensagem", new { placeholder = "Mensagem", @class = "form-control" })
                    </div>
                    <input type="submit" value="Enviar" class="btn btn-default" />
                    <div class="telefone"><strong>TELEFONE PARA CONTATO:</strong> 11 4421-3426</div>
                }
        }
    </div>
</section>

Note: It always occurs when you have $(document).ready(function () ... . If I know how to solve this, the others who accuse the same thing, I will succeed.

    
asked by anonymous 01.09.2016 / 21:07

1 answer

8

This problem can be caused by some factors:

  • Order where scripts are included. If you put javascript that uses jQuery before jQuery is added, jQuery will not have been loaded, causing this error.
  • Example:

    <script>
      $(function () {
          $('#item').click(function () {
              alert('olá');
          });
      });
    </script>
    <!-- errado o jQuery deveria estar antes -->
    <script src="js/jquery.js"></script>
    
  • jQuery has not been included. You may have accidentally removed the snippet of code that included the jQuery script.

  • Linked jQuery script path does not exist. You may have renamed or placed the wrong way by trying to point to jQuery.

  • These are causes that I raised, taking into consideration that the error was on the part of who is programming. I am not crucifying who misses, just pointing out the points that you can analyze when you come across it.

        
    01.09.2016 / 21:13