|
我有一个登陆的判断,登陆成功之后做页面跳转,怎么样都没办法实现。
PHP复制代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
/*构造函数
*
*
*/
/*
* 登陆界面
*/
function index (){
$data = array();
$this->load->view('_login',$data);
}
function check (){
if ($_POST)
{
if (is_ajax () === TRUE)
{
//echo print_r($_POST);
$username = $this->input->post('username');
$password = $this->input->post('password');
// 把数据提交给模型
$this->load->model('admin_user_model');
$this->admin_user_model->username = $username;
$this->admin_user_model->password = $password;
$users = $this->admin_user_model->check();
if($users)
{
$this->session->set_userdata('logged', true);
$this->session->set_userdata('username', $this->input->post('username'));
$this->session->set_userdata($users);
echo "登陆OK";
//redirect('welcome');
redirect ('blog');
}
else {
echo "is faild";
}
}
else {
echo 'Ajax失败';
}
}
else
{
}
$this->db->last_query();
}
}
复制代码
PHP复制代码
$ (document ).ready (function() {
var $body = $ ('body'),
$content = $ ('#content'),
$form = $content.find ('#loginform');
var username = $ ("#username").val ();
var password = $ ("#password").val ();
//IE doen't like that fadein
if(!$ .browser .msie ) $body.fadeTo (0,0.0).delay (500).fadeTo (1000, 1);
$ ("input").uniform ();
function beforeSubmit ()
{
$ (':input.x-form-required').trigger ('blur');
var numWarnings = $ ('.x-form-invalid').length ;
if (numWarnings ) {
return false;
}
return true;
};
$ ('#loginform').submit (function(){
var username = $ ("#username").val ();
var password = $ ("#password").val ();
$ .ajax ({
type : 'post',
dataType : 'json',
cache : false,
url : "http://localhost/shakeponadmin/index.php/login/check",
data : 'username=' + username + '&password=' + password ,
success :function(result ){
console .log(result );
},
failure :function (result ) {
alert ('Failed');
}
});
return false;
});
});
复制代码
最后在firefox的firebug下面能显示出来
<html><head><title>欢迎进入 http://codeigniter.org.cn</title><head><body>你好,欢迎进入http://codeigniter.org.cn</body></html>
可是页面还是停留在原处,没有执行跳转。
![](http://chrome://livemargins/skin/monitor-play-button.png)
|
|