I want to use jquery's (.load) function in CI, should i place this jquery function in controller, view or js files ? I would basically like to call another file in the views when user click the button
1 Answer
I think its generally considered good practice to keep javascript out of your controllers.
If you need to dynamically build your javascript then do that in your view with something like this:
<script>
$(function() {
$('#result').load('<?php echo site_url('my_controller/json_function')?>/<?php echo $some_value; ?>', function() {
alert('Load was performed.');
});
}
</script>
otherwise it just feels tidier to put all javascript into a js file and pass arguments to it.