表单上传
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'];
//省略数据库查询