未被捕获的ReferenceError:在HTMLButtonElement.onclick上未定义do_login [英] Uncaught ReferenceError: do_login is not defined at HTMLButtonElement.onclick
本文介绍了未被捕获的ReferenceError:在HTMLButtonElement.onclick上未定义do_login的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用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="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>
但是我有此错误消息:
未捕获的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="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
属性优先于标记的主体(请参见
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="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" />
<script type="text/javascript">
function do_login() {
//...
}
</script>
这篇关于未被捕获的ReferenceError:在HTMLButtonElement.onclick上未定义do_login的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文