悟性不高。。待指点只上关键些的代码。Login.htmlvar URL = '__URL__';
$.ajax({ //一个Ajax过程
type: "post", //以post方式与后台沟通
url : URL+'/checkLogin/',
dataType:'json',//从php返回的值以 JSON方式 解释
data: {username: $(".username").val(), password: $(".password").val(), verify: $(".inputer").val()},
async : false, //默认为true 异步
timeout: 3000,
success: function(data, str){
$("<font color='red'>"+username+"</font>").appendTo("#result");
},
error: function(){
alert("fail !!!");
}
});
<input type="text" name="username" class="username">
<input type="password" name="password" class="password">
<input type="text" name="verify" class="inputer">
<div id="result"></div>
LoginAction.class.php class LoginAction extends Action {
public function index() {
$this->display('Index:Login');
}
public function checkLogin() {
$var = $_POST;
if(empty($_POST['username'])) {
$this->ajaxReturn($var, '用户名必填', 0);//用户名
}else if(empty($_POST['password'])) {
$this->ajaxReturn($var, '密码必填', 0);//用户名
}else if($_SESSION['verify'] != $_POST['verify']){
$this->ajaxReturn($var, '验证码错误', 0);//验证码
}
}
}
错哪了?望大虾指教
$.ajax({ //一个Ajax过程
type: "post", //以post方式与后台沟通
url : URL+'/checkLogin/',
dataType:'json',//从php返回的值以 JSON方式 解释
data: {username: $(".username").val(), password: $(".password").val(), verify: $(".inputer").val()},
async : false, //默认为true 异步
timeout: 3000,
success: function(data, str){
$("<font color='red'>"+username+"</font>").appendTo("#result");
},
error: function(){
alert("fail !!!");
}
});
<input type="text" name="username" class="username">
<input type="password" name="password" class="password">
<input type="text" name="verify" class="inputer">
<div id="result"></div>
LoginAction.class.php class LoginAction extends Action {
public function index() {
$this->display('Index:Login');
}
public function checkLogin() {
$var = $_POST;
if(empty($_POST['username'])) {
$this->ajaxReturn($var, '用户名必填', 0);//用户名
}else if(empty($_POST['password'])) {
$this->ajaxReturn($var, '密码必填', 0);//用户名
}else if($_SESSION['verify'] != $_POST['verify']){
$this->ajaxReturn($var, '验证码错误', 0);//验证码
}
}
}
错哪了?望大虾指教
加群中国php军团(7948162)
具体报什么错你还是说清楚
function 里面用username
最好是把报的错误发一下