2017-02-27 30 views
2

PHP、AJAX、およびMySqlを使用して簡単なログインページを開発しようとしています。 そして長い闘いの後、私はこれでした:Uncaught ReferenceError:HTMLButtonElement.onclickでdo_loginが定義されていません

<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>タグの

<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> 

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

にそれを変更してみてくださいそれは私が私がボタンタグ内do_login()を呼び出すときに問題があると思います。 "トン作業をdoesnの。何あなたはどう思いますか? –

関連する問題