Consider the following:
<div id="BAN">
<script type="text/javascript">
var nextTimes = 0;
window.onload = function() {
acquireComments();
nextTimes= nextTimes+10;
};
function acquireComments(){
var artID = "<?php echo $GOTID; ?>";
var currentvalue = document.getElementById('BAN').innerHTML;
//console.log(currentvalue);
$.ajax({
type: "GET",
url: 'recieveComments.php?article=2&time='+nextTimes+'',
success: function(data){
document.getElementById('BAN').innerHTML = data;
}
});
}
</script>
</div>
And in the receivecomments.php file:
echo "<div id=\"CommentDiv\" style=\"margin-top:10px;webkit-text-size-adjust:none;-ms-text-size-adjust:none; -moz-text-size-adjust:none;text-size-adjust:none;\">
<a id=\"alink\" style=\"font-size:16px;webkit-text-size-adjust:none;-ms-text-size-adjust:none; -moz-text-size-adjust:none;text-size-adjust:none;\"href=\"$url\">$name</a>
<p style=\"webkit-text-size-adjust:none;-ms-text-size-adjust:none; -moz-text-size-adjust:none;text-size-adjust:none;\">$comment</p>
<div id=\"ReplyComment\">
<a id=\"Reply\">Reply</a>
<script type=\"text/javascript\">
setInterval(function test(){
console.log(\"Hello World\");
},10);
</script>
</div>
</div>";
The above code in the recievecomments.php file is echoed and is displayed on screen. However the console does not log "Hello World". I printed the innerhtml of the "BAN" div and it appears that the java script code is in their but it is not getting executed. I tried putting in an alert instead and I tried making it change the CSS but still does not work. Can anyone point out what I am doing wrong. I am using PHP 5.5