1

I have 10 views in my codeigniter's views folder. I am currently using javascript for implementing ajax. I have implemented ajax in codeigniter and for using post request i had to use

<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>

this code which will generate the csrf code for me.

Since for using php tags inside js i have written the js inside the view's php file. But due to this i have to write the same ajax function in all 10 views which is just waste of code when i can separate the js in single file and include it everywhere.

I've tried using php tags in separate js file which led me to errors. Is there any way to deal with that or i have to write same code in all the views again and agian?

4
  • Try to rephrase your question Commented Oct 11, 2013 at 12:55
  • Just rewritten, check it out please! Commented Oct 11, 2013 at 13:01
  • 1
    so just write another view with your code which is replicated in each view and load that view in your other views Commented Oct 11, 2013 at 13:06
  • that is brilliant actually, haven't even thought about that. write it in answer so that i can accept it as answer. thanks btw Commented Oct 11, 2013 at 13:10

1 Answer 1

1

I would write another view and load it wherever I need to replicate the code.

$this->load->view('my_replicated_view');
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.