Javascript only works on the home page - codeigniter
Just wanted to stop by and ask if anybody has had this problem.
I’m setting up a site with codeigniter and for some weird reason javascript only works on the home page. I’m loading the views dinamically, like so:
$this->load->view('includes/header');
$this->load->view($main_content);
$this->load->view('includes开发者_StackOverflow中文版/footer');
If I click on a link that takes me to http://localhost/site/index, javascript works just fine, but if from there I click a link that takes me to http://localhost/site/about, javascript does not work any longer.
I know the files are there because I’m only switching the view with the $main_content variable, and when I inspect the site in firebug everything seems to be there, loaded and available.
Also tried the
redirect('/site/about', 'refresh');
and it would just not work.
Any ideas?
Thanks
I'm answering my own question for anybody that has a similar problem.
The problem was that I was loading all my js files regardless of what view was being loaded. And javascript was silently failing because it was trying to find DOM elements that were not there in every page. In my experience with regular projects, javascript (jquery) in this case, just ignores it and continues. In this case it was just failing without throwing errors.
精彩评论