我正在尝试使用PHP,AJAX和MySql开发一个简单的登录页面.经过长时间的努力,我做到了:
I am trying to develop a simple login page , using PHP , AJAX and MySql. And after a long struggle , I did this :
<head> <link rel="stylesheet" type="text/css" href="css\\login.css"> <script src="ajax.googleapis/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>但是我有此错误消息:
未捕获的ReferenceError:在HTMLButtonElement.onclick上未定义do_login
Uncaught ReferenceError: do_login is not defined at HTMLButtonElement.onclick
推荐答案您的< script> 标记同时具有主体和 src 属性.
Your <script> tag has both a body and a src attribute.
<script src="ajax.googleapis/ajax/libs/jquery/1.11.1/jquery.min.js"> // This is the body of the script tag function do_login() { //... } </script>< script> 标记的 src 属性优先于标记的主体(请参见 JavaScript:具有SRC属性的内嵌脚本?).因此,这意味着实际上从未定义您的 do_login 函数:(
The src attribute of the <script> tag has precedence over the body of the tag (see JavaScript: Inline Script with SRC Attribute?). So this means your do_login function is never actually being defined :(
尝试将其更改为
<script type="text/javascript" src="ajax.googleapis/ajax/libs/jquery/1.11.1/jquery.min.js" /> <script type="text/javascript"> function do_login() { //... } </script>更多推荐
未被捕获的ReferenceError:在HTMLButtonElement.onclick上未定义do
发布评论