Reputation: 17
Looking for a way to call a php function that has its include 'functions.php' in the original file.
This is what is in my index.php file, so when i click on a link it will load (new.php) into the (#container) div.
<?php include 'functions.php' ?>
<script type="text/javascript">
$(document).ready(function() {
$('a').click(function(e) {
$('#container').load(new.php).hide().fadeIn(500);
return false;
});
});
</script>
So in my new.php, i want to call a function that is located in functions.php, but obviously i get an undefined error.
<?php some_func() ?>
I know you can just put another include 'functions.php' inside the new.php
but since the functions.php contains mysql connections/queries and other includes etc.. i dont really want to keep reloading it.
so is there any way i can reload the functions.php into the newly loaded div and call functions from it?
Upvotes: 0
Views: 741
Reputation: 2125
When you "load" new.php inside your div, you're only loading the resulting HTML code into the div.
The resulting HTML code, in that case, will be the result of the PHP processing of new.php's, code, which depends on functions inside functions.php.
In that case, acessing the content of a file using javascript, there is absolutely no way to do that but placing include 'functions.php';
inside new.php.
Both files will be processed individually. new.php will not run "inside" index.php and therefore will not be able to access whatever functions are defined there.
Upvotes: 1