这是之前js的ajax的例子用jquery实现了一遍,比较一下,对两者有更深入的了解
js的实现链接
http://blog.chinaunix.net/uid-28561809-id-5673877.html
前端代码
-
<!DOCTYPE html >
-
<html>
-
<head>
-
<title>task</title>
-
<script src=""></script>
-
</head>
-
<body>
-
<p><label>用户名</label><input type="text" id="username"/></p>
-
<p><label>密码</label><input type="password" id="password"/></p>
-
<p><input type="submit" value="submit" class="btn"/></p>
-
</body>
-
</html>
-
<script language="javascript" type="text/javascript">
-
$(".btn").click(function(){
-
console.log($("#username").val());
-
$.ajax({
-
type:"POST",
-
url:"dologin.php",
-
-
data:{
-
username:$("#username").val(),
-
password:$("#password").val()
-
},
-
success:function(data){
-
console.log(data)
-
if(data =="ok"){
-
alert("true");
-
}else{
-
alert ("false");
-
}
-
}
-
});
-
})
-
</script>
后台代码
dologin.php
-
<?php
-
session_start();
-
if($_POST['username']&&$_POST['password']){
-
$name = $_POST['username'];
-
$pass = $_POST['password'];
-
if($name=='ella' && $pass = 'pass'){
-
-
echo "ok";
-
-
}else{
-
echo "error";
-
}
-
}else{
-
echo 'error';
-
exit;
-
}
-
?>
阅读(776) | 评论(0) | 转发(0) |