Reputation: 5309
Jquery/Javascript
are not working in codeigniter. What i did is
In config.php
I include
$config['javascript_location'] = 'libraries/javascript/jquery.js';
$config['javascript_ajax_img'] = 'images/ajax-loader.gif';
In controller/welcome.php
I include
public function __construct()
{
parent::__construct();
$this->load->library('javascript');
$this->load->library('javascript/jquery');
}
public function index()
{
$data['library_src'] = $this->jquery->script();
$data['script_head'] = $this->jquery->_compile();
$this->load->view('register', $data);
}
In views/register.php
I include
<?php $this->jquery->click('#username', $this->jquery->alert("hi")); ?>
But nothing is happened. No error displayed. How can I make jquery/Javascript
events in Codeigniter
. Question related to this are asked by others but i can't find a solution yet. So don't marked this as duplicate.
Thanks.
EDIT
Any alternative way(any way) for working jquery in CI. Simply how can i make work jquery in CI.
Upvotes: 0
Views: 562
Reputation: 7916
I advice you to use jQuery as javascript not the version included with codeigniter because it my be an old version you can but your javascript libraries in new folder called asset/js on root of project
and include them in view as follows
<html>
<head>
<script src="<?=base_url()?>/assets/js/jquery.js" type="text/javscript"></script>
<script>
$(document).ready(function(){
$("#username").click(function(){
//your code here
});
});
</script>
</head>
Upvotes: 1