2013-05-16 82 views
-1

检查了这一点。jquery mobile和追加/注入HTML

<?php 
    include('configdb.php'); 
    if(isset($_POST['submit'])) { 
    $email = trim($_POST['email']); 
    $password = trim($_POST['password']); 
    $query = "SELECT * FROM user WHERE email='$email' AND password='$password' AND com_code IS NULL"; 
    $result = mysqli_query($mysqli,$query)or die(mysqli_error()); 
    $num_row = mysqli_num_rows($result); 
    $row = mysqli_fetch_array($result); 

     if($num_row == 1) { 
     $_SESSION['user_name']=$row['username']; 
     header("Location: member.php"); 
     exit; 
     } 

     else { 
    ?> 
     <script type="text/javascript"> 
     $('.error').append('This will display if there was an error'); 
     </script> 
    <?php  
     } 
    } 
    ?> 

<div data-role="content" data-theme="b"><p class="error"></p></div> 

因此,作为一名新手,我正在玩弄并试图弄清楚为什么某些事情会发挥作用,为什么其他人不会。

这里的想法是,如果数据库检查失败,jQuery会向错误类的段落标记中注入一条消息。 (你不能那样用PHP echo你能吗?)

很好用,直到我添加jQuery Mobile框架。然后它所做的只是刷新而没有更新。我无法弄清楚为什么移动框架正在防止这种情况发生。

任何意见,将不胜感激。多谢你们。

回答

0

为什么你不能使用PHP来做到这一点?它看起来很琐碎:

<?php if (isset($num_row) && $num_row == 0) { ?> 
    <div data-role="content" data-theme="b"> 
    <p class="error">This will display if there was an error</p> 
    </div> 
<?php } ?>