表單上傳
html:
<form action="php地址" method="post">
<label>
用戶名: <input type="text" name = "user">
</label>
<br>
<label>
密 碼: <input type="password" name="pwd">
</label>
<br>
<input type="submit" value="提交" id="btn">
</form>
<span id="info">用戶名或者密碼錯誤</span>
js:
$('form').on('submit',function(e){
e.preventDefault();
})
$("#btn").on("click",function(e){
//用ajax上傳
$.ajax({
type:"POST",
url: php地址 ,
data:{
user:$.trim($('input[name=user]').val()),
user:$.trim($('input[name=pwd]').val()),
},
dataType:'json',
success:function(res){
console.log(res);
//status==1時上傳成功
if(res.status==1){
setTimeout(function(){
location.href = "success.html";
},3000);
}else{
$("#info").show();
}
},
//錯誤信息
error:function(err){
console.log(err);
}
})
})
php:
header("Content-Type:text/html;charset=utf8");
$user = $_POST['user'];
$pwd = $_POST['pwd'];
//省略數(shù)據(jù)庫查詢