2012-08-29 38 views
1
<!DOCTYPE HTML> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>Amateur</title> 
    <link rel="stylesheet" href="css/reset.css" type="text/css"> 
    <script src="http://code.jquery.com/jquery-1.8.0.js"> 
     function check_email() 
     { 
      var email=$("#txtEmail").val(); 
      $.ajax(
      { 
       type:"POST"; 
       url:"index.php"; 
       data:"email="+email, 
       success:function(msg) 
       { 
        $("#chkEmail").html(msg); 
       } 
      }); 

      return false; 
     } 
    </script> 
</head> 

<body> 
<form method="post"> 
    <label for="txtEmail">E-mail:</label> 
     <input id="txtEmail" name="email" type="email" onblur="return check_email()"> 
    <label id="chkEmail" for="txtEmail"></label> 
    <?php 

    if(isset($_POST['email'])) 
    { 
     $user='root'; 

     $pdo=new PDO('mysql:host=localhost;dbname=class;charset=utf8',$user); 

     $email=$_POST['email']; 

     $stmt=$pdo->prepare('SELECT email from tbl_users WHERE email=:email LIMIT 1'); 
     $stmt->execute(array(':email'=>$email)); 

     if($stmt->rowCount()>0) 
     { 
      echo 'E-mail already use.'; 
     } 
     else 
     { 
      echo 'E-mail not use.'; 
     } 

    } 

    ?> 
</form> 
</body> 
</html> 

我仍然在PHP和JQuery首發我想知道如何解決這種類型的錯誤?我從螢火蟲中檢查它。流程是用戶輸入完電子郵件後,它會自動從數據庫中檢查是否存在。預期的輸出不會顯示在我的頁面中。如何解決這種類型的錯誤:「未捕獲的ReferenceError:check_email沒有的onblur定義爲」

+0

'$(#chkEmail)的.html(MSG);'應該是'$( 「#chkEmail」)HTML(MSG);' –

+0

什麼都沒有發生:( - –

回答

2

你錯過了上選擇報價,分隔條件的AJAX功能參數之間用分號,而不是逗號等

function check_email() { 
     var email=$("#txtEmail").val(); 
      $.ajax({ 
       type:"POST", 
       url:"index.php", 
       data: {email: email}, 
       success:function(msg) { 
        $("#chkEmail").html(msg); 
       } 
      }); 
      return false; 
     } 
+0

。什麼都沒有發生:( - –

0
<script src="http://code.jquery.com/jquery-1.8.0.js"> 
    function check_email() 
    { 
     var email=$("#txtEmail").val(); 
     $.ajax(
     { 
      type:"post", 
      url:"index.php", 
      data:"email="+email, 
      success:function(msg) 
      { 
       $("#chkEmail").html(msg); 
      } 
     }); 

     return false; 
    } 
</script> 
+0

你需要改變分號(;)參數之間的逗號(,)也 – Scott

+0

謝謝,錯過了:) –

+0

所有分號到逗號?什麼$(#id)? –

0

編輯

$.ajax(
     { 
      type:"post"; 
      url:"index.php"; 
      data:"email="+email, 
    success:function(msg) 
        { 
         $(#chkEmail).html(msg); 
        } 
      **TO** 
$.ajax(
     { 
      type:"POST", 
      url:"index.php", 
      data:{email:email}, 
success:function(msg) 
       { 
        $('#chkEmail').html(msg); 
       } 
+0

仍然沒有, t工作:( - –

+0

@BrainedWashed現在檢查這是行不通的,然後檢查通過使用Firebug或Chrome Javascript控制檯檢查是否仍然有錯誤的Javascript –

+0

我使用chromes js控制檯仍然是相同的錯誤 –

1

添加另一個<script>標籤,這不是正確的方式來添加js源文件,並在相同的代碼中編碼。

<script src="http://code.jquery.com/jquery-1.8.0.js"></script> 
<script> 
     function check_email() 
     { 
      var email=$("#txtEmail").val(); 
      $.ajax(
      { 
       type:"POST"; 
       url:"index.php"; 
       data:"email="+email, 
       success:function(msg) 
       { 
        $("#chkEmail").html(msg); 
       } 
      }); 

      return false; 
     } 
    </script> 
+0

這有幫助嗎? –

+0

我試過了,但錯誤仍然存​​在:( –

0
<script src="http://code.jquery.com/jquery-1.8.0.js"></script> 
    <script> 
     var checkEmail= function() 
     { 
      var email=$("#txtEmail").val(); 
      $.ajax(
      { 
       type:"POST", 
       url:"index.php", 
       data:"email="+email, 
       success:function(msg) 
       { 
        $("#chkEmail").html(msg); 
       } 
      }); 

      return false; 
     } 
    </script> 
</head> 

<body> 
<form method="post"> 
    <label for="txtEmail">E-mail:</label> 
     <input id="txtEmail" type="email" onblur="javascript:checkEmail();"> 
    <label id="chkEmail" for="txtEmail"></label> 

</form> 
</body> 

添加到onblur="javascript:checkEmail();和我犯了一個功能有點不同,它宣佈變種。

0

將jquery源代碼放在單獨的腳本上。確保爲腳本放置了結束標記(不是自閉標記)。

使用逗號作爲參數,而不是分號。

試試這個:

<script src="http://code.jquery.com/jquery-1.8.0.js"></script> 
<script type="text/javascript"> 
    function check_email() 
    { 
     var email=$("#txtEmail").val(); 
     $.ajax(
     { 
      type:"POST", 
      url:"index.php", 
      data:"email="+email, 
      success:function(msg) 
      { 
       $("#chkEmail").html(msg); 
      } 
     }); 

     return false; 
    } 
</script> 
+0

@ brained-washed,我認爲這適用於你?:) – jovani

相關問題