Reputation: 3433
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?
Upvotes: 1
Views: 246
Reputation: 4292
I would write another view and load it wherever I need to replicate the code.
$this->load->view('my_replicated_view');
Upvotes: 1