I have put the following javascript test code but it does not run after loading the page with AJAX.
<script> alert('hi'); </script>
My AJAX code (in functions.js):
function mostrarAJAX(enlace, elem)
{
$.ajax
({
url: enlace,
cache: false,
beforeSend: function() { $(elem).html('<br /><center style="margin-
top: 50px;"><span style="margin-right:8px;"></span><img
src="../images/loading.gif" /><div style="font-size: 20px;margin-
top: 25px;">Loading...</div></center>'); },
error: function(xhr) { $(elem).html(xhr.status + ' ' + xhr.statusText); },
success: function(result){ $(elem).html(result); }
});
}
When I run the AJAX, the page is displayed, but the script is not executed. The thing is that part of the javascript I generate it from PHP with echo, since it is a statistic chart.
Hunk of the real javascript (in stats.php):
data:
[
<?php
$resultstats = mysqli_query($con, $sqlstats);
$countstats = mysqli_num_rows($resultstats);
for($i = 0; $i < $countstats; $i++)
{
$rowstats = mysqli_fetch_array($resultstats);
if($i < ($countstats - 1))
echo '{date: "'.$rowstats['Date'].'", value: '.$rowstats['TotalMembers'].'}, ';
else
echo '{date: "'.$rowstats['Date'].'", value: '.$rowstats['TotalMembers'].'}';
}
?>
],
The PHP script runs correctly by filling in the javascript array with the statistics for the graph but the problem is that the javascript is not executed, so the graph is not displayed. When I run the graph without AJAX, the graph works correctly.
Any ideas?
Thanks in advance.