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?
 
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
 
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.