我正在尝试使用PHP,AJAX和MySql开发一个简单的登录页面。 经过长时间的斗争,我做到了这一点:
<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
答案 0 :(得分: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>
src
标记的<script>
属性优先于标记正文(请参阅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>