Evaluate PHP after dynamically loading into a div

Hi Experts,
I have the following php file called directions.php

<?php
echo('<script src="http://www.gmodules.com/ig/ifr?url=http://hosting.gmodules.com/ig/gadgets/file/114281111391296844949/driving-directions.xml&amp;up_fromLocation=&amp;up_myLocations=POSTCODE&amp;up_defaultDirectionsType=&amp;up_autoExpand=&amp;synd=open&amp;w=320&amp;h=55&amp;title=Directions+to+EMU+TA+Centre&amp;brand=light&amp;lang=en&amp;country=GB&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script>');

?>

Open in new window



I have a dynamic page on my site that loads code from a MySQL database into the contents of a <div>

using the following javascript
function getContent(str)
{
if (str=="")
{
document.getElementById("contentarea").innerHTML="";
return;
} 
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("contentarea").innerHTML=xmlhttp.responseText;
}
if (xmlhttp.readyState<4)
{
document.getElementById("contentarea").innerHTML="<p><i>Loading....</i></p>";
}
}
xmlhttp.open("GET","getcontent.php?q="+str,true);
xmlhttp.send();
}

Open in new window


Now, if i open getcontent.php?q=PageName i get the following response:

<html><h2> My content </h2>
<p> my content </p>
<?php include("directions.php");  ?></html>

Open in new window

.

But the php does not render. The directions applet is not showing. If hardcode the <?php include("directions.php");  ?> into the page before any dynamic loading is done the applet shows.

Do i need to tell the page somehow to re-evaluate the php after it is loaded into the <div>? How would I do that?

Many thanks,
LVL 1
FragReaperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tsmgeekCommented:
looks like your webserver does not support php or its not configured to understand .php as a PHP app
0
FragReaperAuthor Commented:
PHP is configured, as getContent.php produces the correct output.
0
leakim971PluritechnicianCommented:
>as getContent.php produces the correct output.

@tsmgeek is right, line 3 you've : tsmgeek <?php include("directions.php");  ?>

you should not see this
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

FragReaperAuthor Commented:
Just to clarify - the one page of the website index.php does not initially have the <script> object inside it, but a hyperlink calls an ajax script that sets the contents div .innerhtml to the response of getcontents.php ( which gets the code, stored as plain text, from mysql. The problem arises when this code in the database contains <script> or php. HTML loads fine dynamically.
0
Dave BaldwinFixer of ProblemsCommented:
You can't load PHP after the page is loaded because PHP only executes on the server.  And you are no longer on the server at that point.  You can have the PHP code <?php include("directions.php");  ?> execute on the server and return the information.  But after the page is loaded, any PHP code you load into the page will not execute because it is no longer on the server.  Browsers can't run PHP.  Only the server runs PHP.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.