Codeigniter does not read jquery

I am trying to include jquery in my codeigniter application. To do this, I created a js folder inside the codeigniter folder, where I put two files. Jquery.js with code to run jquery and another duplicate.js file where I have the following code to see if the jquery page is running.

window.onload = function() { if (window.jQuery) { // jQuery is loaded alert("Yeahsssss!"); } else { // jQuery is not loaded alert("Doesn't Work"); } } 

Then in the headr template of my views, I have:

 <html> <head> <title></title> <meta http-equiv="content-type" content="text/html;charset=UTF-8"> <link rel="stylesheet" href="<?php echo base_url();?>css/mystyle.css" type="text/css" media="screen"/> <script type="text/javasript" src="<?=base_url()?>js/jquery.js"></script> <script type="text/javasript" src="<?=base_url()?>js/duplicate.js"></script> </head> <body> 

Should this not be enough to run jquery on pages? Did I miss something?

EDIT:

head section generated:

  <head> <title> - CodeIgniter 2 Tutorial</title> <meta http-equiv="content-type" content="text/html;charset=UTF-8"> <link rel="stylesheet" href="http://localhost/code/css/mystyle.css" type="text/css" media="screen"/> <script type="text/javasript" src="http://localhost/code/js/jquery.js"></script> <script type="text/javasript" src="http://localhost/code/js/duplicate.js"></script> </head> 
0
source share
2 answers

you have a typo: text/javasript must be text/javascript

depending on the type that is defined for the script, the browser determines what the script is and how to handle it. therefore, if this type is incorrect, the browser will not interpret the contents of the script if it is an inline script or load its source if it has the src attribute.

+4
source

Move jquery outside the controller folder and put it in a folder of type assets .

Normal CodeIgniter structure:

  • application
  • system
  • user_guide

add the folder there:

  • application
  • system
  • user_guide
  • assets

inside the assets folder add another js folder or whatever to keep your javascript libraries and code.

then include your js files, for example:

 <script src="<?php echo base_url("assets/js/jquery-1.8.2.min.js")?>"></script> 

which will look like this:

http://hostname.com/project_name/assets/js/jquery-1.8.2.min.js

+1
source

All Articles