如何在bootstrap模式中显示成功或错误消息?

时间:2017-01-18 15:55:13

标签: php twitter-bootstrap

HTML CODE:

<li class="llogin">
   <a class="mlogin" data-target="#loginmodal" data-toggle="modal"><span class="glyphicon glyphicon-chevron-down pull-right"></span>Login</a>
   <div class="modal" id="loginmodal" tabindex="-1">
      <div class="modal-dialog">
         <div class="modal-content">
            <div class="modal-header">
               <button class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body">
               <div class="form-group">
                  <input type="text" name=username id="username" placeholder="username" value="" class="form-control" />
               </div>
               <div class="form-group">
                  <input type="password" name=password id="password" placeholder="password" value="" class="form-control" />
               </div>
               <div class="form-group">
                  <div class="row">
                     <div class="text-center" class="col-md-6">
                        <input type="submit" name="loginsubmit" id="loginsubmit" class="form-control btn btn-info" value="LogIn" style="width:20%">
                     </div>
                  </div>
               </div>
               <div id="loginresult" class="alert-success"></div>
            </div>
            <div class="modal-footer">
               <button class="btn btn-primary" data-dismiss="modal">Close</button>
               <button class="btn btn-primary">Login</button>
            </div>
         </div>
      </div>
   </div>
</li>

AJAX代码:

$("#loginsubmit").click(function(){
    var username = $("#username").val();
    var password = $("#password").val();

 $.ajax({

    type:'POST',
    data: {username:username,password:password},
    url:'login.php',
    success:function(logged)
    {
        $("#loginresult").html(logged);
        $('#loginmodal').modal("show");

    },

 })
})

我正在使用 PHP 构建网络商店。我希望在bootstrap模式中显示消息,但不知道上述代码中出现了什么问题。

请建议我应该做些什么改变才能达到预期的行为。

我收到没有模态的消息,但我想以模态显示消息。

2 个答案:

答案 0 :(得分:0)

<?php
require_once("config.php"); 
if(isset($_REQUEST['username']))
{
    $username= $_REQUEST['username'];
    $password= $_REQUEST['password'];
//echo $username;

$con = mysqli_connect(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME);
if($con)
{
$sql = "SELECT `username`,`password` FROM `register` WHERE `username`=? AND `password`=?";
$obj = mysqli_prepare($con,$sql);
if(is_object($obj))
{
    mysqli_stmt_bind_param($obj,"ss",$username,$password);
    mysqli_stmt_bind_result($obj,$myuser_name, $mypassword);
    mysqli_stmt_execute($obj);
    mysqli_stmt_store_result($obj);
    mysqli_stmt_fetch($obj);
    if($myuser_name == $username && $mypassword == $password)
    {
        echo "Successfully Logged In";
    }else{
        echo "Logged In failed";
    }
}else{
    echo "Not Object";
}

}else{
    echo "db problem";
}
}else{
    echo "value not set";
}


 ?>

here is PHP Code.

答案 1 :(得分:0)

我找不到ID为“登录模式”的div&#39;你的HTML。也许这是缺少的?