Forum Moderators: open
File1:
<html>
<body>
<script>
function reload(){
var oRequest = new XMLHttpRequest();
var sURL = "http://"+self.location.hostname+"/media/2.php";
oRequest.open("GET",sURL,false);
oRequest.setRequestHeader("User-Agent",navigator.userAgent);
oRequest.send(null)
document.getElementById("new").innerHTML = oRequest.responseText;
setTimeout("reload()",4000);
}
window.onload = reload;
</script>
<div id="new"></div>
</body>
</html>
File2 2.php - the one included
<div><script>
var rand_no = Math.random();
document.write(rand_no);
</script>
file2</div>
This test version of the code should retrieve a obviously inside the <div id="new"></div> a random number followed by the text "file2", but only retrieves the text file2.
In other words all that is dynamically generated in the inclusion file is being stripped off.
Any ideas?
im loading an html file into a div
(and also fading out old content, and in with new content)
and it works fine until the html file i load into the div trys to access dynamic data from an xml file, in which case all i get are the variable names displayed.
i understand why the javascript isnt being processed, but i thought that the spry framework would have a solution for this....
first of all javascript can be processed, but you have to break it down:
<script>
var divjs = "var rand_no = Math.random();
document.write(rand_no);"
divTag.innerHTML ="<script>"+ divjs+"<\/script>";
</script>
i used this on another website and it works.
the problem with processing javascript from javascript is that end tag </script> it closes the script to early. You have to either escape the slash <\/script> or break it: "</sc"+ript>";
to:delboy1978uk
for your problem i suggest pre-loading the stuff you want shown(if it's not to big) and put in another hidden div:
<div id="hidden" style="display:none;> data from xml</div>
<div id="visible"> old content</div>
<script>
function swap()
{
document.getElementbyID.("hidden").style.display.block;
document.getElementbyID.("visible").style.display.none;
}
setTimeout("swap()",5000)
</script>
not sure about the syntax.
That is if you only want to change the content once.
to daveVk
how do you suggest doing it in php?
[edited by: engine at 7:57 am (utc) on June 23, 2009]
[edit reason] No urls, thanks, see WebmasterWorld TOS [/edit]