Javascript not running when called from an Ajax script
Posted: Fri Oct 19, 2007 4:05 am
I have a page with an Ajax script included which retrieves the contents of another page every 10 seconds and displays the contents. In the page that is retrieved I have a bit of Javascript, as a test I've just used the alert() function and also document.write. But none are being run. It doesn't work in IE nor Firefox and the Firefox error console gives no errors at all.
The Ajax script it:
And page.php contains:
If I go directly to page.php I get both the popups, but they are not used when called from the Ajax script.
Any ideas why this is?
The Ajax script it:
Code: Select all
function ajaxFunction(){
var ajaxRequest;
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
try{
ajaxRequest = new
ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new
ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementById('myDiv').innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "http://my.page/page.php", true);
ajaxRequest.send(null);
}
Code: Select all
<body>
<script type = 'text/javascript'>
alert('Ello')
</script>
<?php
echo time();
echo "<script> alert('boo') </script>";
?>
Any ideas why this is?