ajax在IE中不起作用

时间:2013-11-21 12:39:39

标签: ajax codeigniter internet-explorer jquery

我正面临Ajax登录问题..它在Chrome和Firefox中运行良好但在IE中却没有 即使用户名和密码正确,它也总是显示我的密码错误。

顺便说一句,我正在使用codeigniter

这是HTML

<form id="login_form" method="post" >
    <strong id="validation_feedback" class="row-fluid"> Please enter your username and password</strong>


      <div class="form_separator"></div><br />
    <p class="row-fluid">
    <label><i class="d-icon-user"></i> &nbsp;&nbsp;USERNAME</label>
    <input class="span12" type="text" id="username" name="username" placeholder="Username..." />
    </p>
    <p class="row-fluid">
    <label><i class="d-icon-lock"></i> &nbsp;&nbsp;PASSWORD</label>
    <input class="span12" type="password" id="password" name="password" placeholder="Password..." />
    </p>

    <input class="btn btn-warning" style="width:100%; float:right;" type="submit" value="SIGN IN" id="submit_login" /> 

</form>

以下是Ajax代码:

<script type="text/javascript">
  $(document).ready(function() {

    $('#login_form').submit(function(e) {

        e.preventDefault();
        $('#validation_feedback').html("Checking ... ");
        $('#submit_login').attr("disabled" , "disabled");
        var inputs  = {
          username: $('#username').val(),
          password: $('#password').val()
        };

        $.ajax({
          url: "<?php echo site_url('main/login2'); ?>",
          type: 'POST',
          data: inputs,
          success: function(msg){
            alert('as');
            if( msg == "false" ){
              $('#validation_feedback').html("Wrong username or password .. try again");
              $('#submit_login').removeAttr("disabled");
            }
            else{
              location.reload();
              $('#validation_feedback').html("Logged in successfully ");
              $('#submit_login').removeAttr("disabled");
            }
          }

        });

    });

  });

</script>

以下是Controller中检查用户名和密码的功能

function login2(){
    $this->load->library('form_validation');

    $this->form_validation->set_rules('username', 'Username', 'required|trim|xss_clean|callback_validate_user');
    $this->form_validation->set_rules('password', 'Password', 'required|md5|trim|xss_clean');

    if($this->form_validation->run()){

        $this->load->model('User');

        $info = $this->User->getUserInfo($this->input->post('username'));
        $data = array(
                  "user" => $this->input->post('username'),
                  "name" => $info->firstname . " " . $info->lastname,
                  "profile" => $info->picture,
                  "timeout" => time()
            );

        $this->session->set_userdata($data);
        redirect('');
    }else{
        //add echo validation_errors(); to view
        echo "false";   
    }
}

0 个答案:

没有答案