2017-02-27 25 views
2

我正在嘗試使用PHP,AJAX和MySql開發一個簡單的登錄頁面。 而長期的鬥爭之後,我這樣做:Uncaught ReferenceError:do_login沒有在HTMLButtonElement.onclick處定義

<head> 
    <link rel="stylesheet" type="text/css" href="css\\login.css"> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> 

        function do_login() 
        { 
        var username=$("#username").val(); 
        var pass=$("#password").val(); 
        if(email!="" && pass!="") 
        { 

         $.ajax 
         ({ 
         type:'post', 
         url:'serveur.php', 
         data:{ 
         do_login:"do_login", 
         username:username, 
         password:pass 
         }, 
         success:function(response) { 
         if(response=="success") 
         { 
         window.location.href="index.php"; 
         console.log(1); 
         } 
         else 
         { 

         alert("Wrong Details"); 
         console.log(0); 
         } 
         } 
         }); 
        } 

        else 
        { 
         alert("Please Fill All The Details"); 
        } 
         return false ; 


        } 

</script> 
</head> 

</style> 
<body> 


<div class="login-page"> 
    <div class="form"> 

    <form class="login-form"> 
     <input type="username" placeholder="username" id="text" /> 
     <input type="password" placeholder="password" id="password" /> 
     <button type="submit" id="loginButt" onclick="do_login()">login</button> 
     <p class="message"><a href="1stPage.html">Go Back</a></p> 
     <div id="resultat ">Authentification result Here ....</div> 
    </form> 
    </div> 
</div> 
</body> 

但我有此錯誤消息:

Uncaught ReferenceError: do_login is not defined at HTMLButtonElement.onclick

回答

1

<script>標籤既有身體和src屬性。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> 
    // This is the body of the script tag 
    function do_login() { 
     //... 
    } 
</script> 

<script>標籤的src屬性具有在標籤體優先(見JavaScript: Inline Script with SRC Attribute?)。因此,這意味着你的do_login功能從來沒有真正被定義:(

嘗試將其更改爲

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" /> 
<script type="text/javascript"> 
    function do_login() { 
     //... 
    } 
</script> 
+0

一點也沒有「T的工作。我認爲這個問題是,當我打電話do_login()按鈕標記內。什麼你認爲 ? –

相關問題