Forum Moderators: open

Message Too Old, No Replies

http request question

         

Simone100

4:19 am on Dec 10, 2006 (gmt 0)

10+ Year Member



Hello, the following is a simple http request that just shows the source code in an alert when you put test.php in the browser, just to show the http request is working. How can I make the exact same http request re-execute after so much time? I tried putting a javascript setTimeout on it but seem to be doing it wrong. How would a setTimeout be attached to this to make the request call again? Or is there a better way than a setTimeout? I really need to get this working. Hope someone can help. Thank you very much.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
<title>test</title>
<style type="text/css">
</style>
<script type="text/javascript" src="http://www.example.com/test.js"></script>
<script type="text/javascript">
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}

xmlhttp.open("GET", "test.php",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
alert(xmlhttp.responseText)
}
}
xmlhttp.send(null)
</script>
</head>
<body>
<div></div>
</body>
</html>

[edited by: encyclo at 1:52 pm (utc) on Dec. 10, 2006]
[edit reason] examplified [/edit]

phranque

9:11 am on Dec 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you could try using the proper http response header:
Refresh: 0; url=http://www.example.com/

or if it is an html document provide it as an html meta tag in the document head:

<meta http-equiv="refresh" content="0; url=http://www.example.com/">

where "0" in both examples is the number of seconds delay before refreshing the document.