javascript - PHP include functions and AJAX div loading -


i have php generated web page, has several divs created using php includes.

<div id ="siteleft" class ="site">     <div id="divgauges"><?php include('gauges.php');?></div>     <div id="divhistory"><?php include('history.php');?></div> </div> <div id="siteright" class ="site">     <div id="divlymgauges"><?php include('gaugeslym.php');?></div>     <div id="divlymhistory"><?php include('historylym.php');?></div> </div> 

these divs reloaded every 10 seconds, using ajax call, in seperate scripts.js file:

function updatehistory(){     $('#divhistory').load('history.php'+"?ms=" + new date().gettime());     $('#divlymhistory').load('historylym.php'+"?ms=" + new date().gettime()); } setinterval( "updatehistory()", 10000 ); 

within history.php , historylym.php, have function call, , function in file called functions.php.

if do:

include ('functions/functions.php'); 

within index.php page, div's display nicely on initial load,

fatal error: call undefined function  

displaying on webpage after ajax call refreshes div history.php , historylym.php (obviously, include function file isn't in div, bit gets called).

so tried putting functions.php include divs loaded. if that, on initial page load get:

fatal error: cannot redeclare getforce() 

which makes sense, on initial load 2 divs both contain include functions.php.

putting include in 1 of divs results in page loading fine (as should do), on ajax refresh of divs, error:

fatal error: call undefined function getforce() 

which again makes sense 2 divs being refreshed independently ajax, , div include functions.php able use function.

so questions is:

where on earth can put include functions.php divs can use functions.php functions on initial page load , on individual seperate ajax refreshes??

first include function file in index.php,
add @ top of include files (ie: gauges.php, history.php, etc..)

<?php   if ( !function_exists( "getforce" ) ) {     // include function file   } ?> 

you can replace getforce other function names defined in function file


Comments