No se ejecuta evento click

publicado por: Anonymous

Estoy tratando de enviar un formulario de una pagina ASPX a AJAX pero no entra a la función del evento click del botón en la parte del JavaScript, le he quitado el runat="server" al formulario pero me genera error; entonces no se cuál sea el error.

_x000D_

_x000D_

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Index.aspx.vb" Inherits="Index" %>_x000D_
_x000D_
<!DOCTYPE html>_x000D_
_x000D_
<html xmlns="http://www.w3.org/1999/xhtml">_x000D_
<head runat="server">_x000D_
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>_x000D_
    <title></title>_x000D_
        <script type="text/javascript">_x000D_
            $(document).ready(function () {_x000D_
                $("#btnEnviar").click(function (e) {_x000D_
                    e.preventDefault();_x000D_
                    $("#lblIncorrectos").html("Procesando...");_x000D_
                    var data = {_x000D_
                        "userid": $("#txtUsuario").val(),_x000D_
                        "password": $("#txtPassword").val(),_x000D_
                        "recordarme": $("#chkRecordar").val()_x000D_
                    };_x000D_
                    $.ajax({_x000D_
                        type: "POST",_x000D_
                        url: "Index.aspx/Login",_x000D_
                        data: data,_x000D_
                        contentType: "application/json; charset=utf-8",_x000D_
                        dataType: "json",_x000D_
                        async: true,_x000D_
                        success: function (result) {_x000D_
                            $("#lblIncorrectos").text(result.d);_x000D_
                        },_x000D_
                        error: function () {_x000D_
                            $("#lblIncorrectos").html("Error");_x000D_
                        }_x000D_
                    });_x000D_
                });_x000D_
            });_x000D_
    </script>_x000D_
</head>_x000D_
<body>_x000D_
        _x000D_
<form id="form1" role="login" runat="server">_x000D_
<span>_x000D_
    <center><img src="img/logo_naranja.gif" class="img-responsive" width="250" height="200" /></center>_x000D_
</span>_x000D_
<h3>Nombre de la Empresa</h3>_x000D_
<div class="form-group">_x000D_
    <!--<asp:TextBox ID="txtUsuario" runat="server" placeholder="Ingrese su usuario" required class="form-control"></asp:TextBox>-->_x000D_
    <input type="text" name="txtUsuario" placeholder="Ingrese su usuario" required class="form-control" />_x000D_
    <span class="glyphicon glyphicon-user"></span>_x000D_
</div>_x000D_
_x000D_
<div class="form-group">_x000D_
    <!--<asp:TextBox ID="txtPassword" runat="server" placeholder="Ingrese su contraseña" required class="form-control" TextMode="Password"></asp:TextBox>-->_x000D_
    <input type="password" name="txtPassword" placeholder="Ingrese su contraseña" required class="form-control" />_x000D_
    <span class="glyphicon glyphicon-lock"></span>_x000D_
</div>_x000D_
_x000D_
<div class="form-group">_x000D_
    <!--<asp:CheckBox ID="chkRecordar" runat="server" value="1" />_x000D_
                    Recordarme ?-->_x000D_
	<input type="checkbox" id="chkRecordar" name="remember" value="1" /> Recordarme ?_x000D_
</div>_x000D_
<!--<asp:Button ID="btnEnviar" runat="server" Text="Entrar" class="btn btn-block btn-primary" />-->_x000D_
<button type="submit" id="btnEnviar" class="btn btn-block btn-primary">Entrar</button>_x000D_
</form>_x000D_
<center><asp:Label ID="lblIncorrectos" runat="server" class="alert alert-danger" rol="alert"></asp:Label></center>           _x000D_
_x000D_
 </body>_x000D_
 </html>

_x000D_

_x000D_

_x000D_

solución

Deberias definir el boton como Type=”button”. O en vez de que el metodo se ejecute al hacer click, que se ejecute en el submit del form1

Cambiar el Tipo:

<button type="button" id="btnEnviar" class="btn btn-block btn-primary">Entrar</button>`

Cambiando El Evento

 <script type="text/javascript">
        $(document).ready(function () {
            $("#form1").submit(function (e) {
                e.preventDefault();
                $("#lblIncorrectos").html("Procesando...");
                var data = {
                    "userid": $("#txtUsuario").val(),
                    "password": $("#txtPassword").val(),
                    "recordarme": $("#chkRecordar").val()
                };
                $.ajax({
                    type: "POST",
                    url: "Index.aspx/Login",
                    data: data,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    success: function (result) {
                        $("#lblIncorrectos").text(result.d);
                    },
                    error: function () {
                        $("#lblIncorrectos").html("Error");
                    }
                });
            });
        });
</script>
Respondido por: Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *