My goal is to pass a jQuery script through a model with CodeIgneter.
This is the view where I linked the jquery.js file
<footer>
<p>© Company 2014</p>
</footer>
<script src="<?php echo base_url('assets/js/jquery.js');?>"> </script>
</div> <!-- /container -->
This is the model jquery
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Jquery extends CI_Model {
public function test(){
return
'<script>
$(document).ready(function() {
$("#submitForm").click(function(){
alert("test");
});
});
</script>';
}
}
In the controller I passed the script as following:
$this->load->model('jquery');
$data['testjs'] = $this->jquery->test();
$this->load->view('login/content',$data);
In the content view I echo the script:
...echo $testjs...
Unfortunately the script does not work as expected.