加载jQuery函数时出错

时间:2016-09-27 06:51:48

标签: javascript jquery asp.net

我有这个代码,会打开一个模态并询问登录信息:

<a href="#" data-toggle="modal" data-target="#login">Login</a>
    <div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Login Area Riservata</h4>
                </div>
                <div class="modal-body">
                    <asp:Label runat="server">Username</asp:Label>
                    <asp:TextBox runat="server" ID="username" CssClass="form-control" TextMode="SingleLine" Placeholder="Inserisci nome utente"></asp:TextBox>
                    <br />
                    <asp:Label runat="server">Password</asp:Label>
                    <asp:TextBox runat="server" ID="password" CssClass="form-control" TextMode="Password" Placeholder="Inserisci password"></asp:TextBox>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                    <asp:Button runat="server" ID="Login" CssClass="btn btn-primary" Text="Login" OnClientClick="Login" />
                </div>
            </div>
        </div>

在“登录”按钮中,我将事件OnClientClick设置为jQuery函数:

$("[id*=Login]").click(function () {
var user = {
    username: $("[id=username]").val(),
    password: $("[id=password]").val()
}
$.ajax({
    type: "POST",
    data: user,
    url: "data_db.asmx/getdatalogindb",
    contenttype: "application/json; charset=utf-8",
    datatype: "json",
    success: OnSuccessLogin,
    failure: function (response) {
        alert("failure: " + response.d);
    },
    error: function (response) {
        alert("error: " + response.d);
    }
  });
});

function OnSuccessLogin(response) {
    var result = response.d;
    if (result = true) {
        //redirect to a page
    } else {
        //set visible = true 2 label for visual error
    }
}

问题1:当我按下登录时,PostBack启动并且我无法阻止它:我想在客户端执行所有事件:如果登录参数是相关的,则重定向到页面,如果错误更改了css对2标签可见,然后重试登录。
问题2:事件没有开始,有时候温暖我,登录不是一个功能 如何解决这个2问题?感谢

0 个答案:

没有答案