I have a codeigniter3 project.
My js-file with a footer include:
<script src="<?= base_url() ?>assets/myjsfile.js"></script>
In the normal codeigniter views, I can work with the file and the functions from it.
If I open a modal and load a new view by an ajax call over the controller, I couldn't work with this js-file. I always receive the error
"Uncaught ReferenceError: myfunctionname is not defined"
in my view, I add a modal-template
<div class="modal fade" id="modal_default" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content"></div>
</div>
</div>
</div>
I load a viewpage onclick into this modal by this controller function
public function_load_content(){
$this->load->view('mycontentfile',$this->input->post());
}
The modal will show and the content also loads correctly.
In this context, I try to call a function on click, which is defined in the "myjsfile.js"
$(document).ready(function(e){
$(document).on('click', '#mybutton', function(){
myfunctionname();
});
});
I tried a lot. Add it into document.ready, move it outside document.ready, add jquery & bootstrap library into the view-file...all my tries failed.
Why i can't access the myfunctionsname()?
In "myjsfile.js" myfunctionname is defined as follows
$(document).ready(function(e){
function myfunctionname(){...}
});
Working on a normal view file which is not loaded later by a ajaxcall runs great.
What do I have to do to make this work and access the file/functions the same way as a normal view?