[eluser]babazumbula[/eluser]
I have jQuery script that works fine on page until certain method is called.
Controller:
Code:
function index(){
$data['main_content'] = 'login_form_view';
$this->load->view('includes/template',$data);
}
View:
Code:
<?php $this->load->view('includes/header'); ?>
<?php $this->load->view($main_content); ?>
<?php $this->load->view('includes/footer'); ?>
At this point everything works fine, my jQuery script is loaded and works as it should.
Now, calling validate_credentials() from the same controller, causes that jQuery stops working. In firebug console I've got error "$ is not defined", and hence js stops working. I checked whether jquery.js is loaded before calling script, and checked if $(document).ready(function(){}) is taking place, but everything seem just fine.
Code:
function validate_credentials(){
$this->load->library('form_validation');
$this->load->model('membership_model');
$this->form_validation->set_rules('username','Username',
'callback_correct_credentials');
if($this->form_validation->run() == false){
$this->index();
}
else{
// some code...
}
}
function correct_credentials(){
$this->load->model('membership_model');
if($this->membership_model->validate()){
return true;
}else{
$this->form_validation->set_message('correct_credentials', 'Incorrect
username/password. Try again') ;
return false;
}
}
In model:
Code:
function validate(){
$this->db->where('username',$this->input->post('username'));
$this->db->where('password',md5($this->input->post('password')));
$query = $this->db->get('membership');
if($query->num_rows() == 1){
return true;
}
else{return false;}
}
Basically function validate_credentials() when executing $this->index() is loading same view again (now with showing login errors), but this time jQuery is not defined, unlike index() is being called by controller at the first place.