0

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 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.