In my last post http://www.tinyclr.com/forum/topic?id=10411&page=2#msg110067 , harleydk gave the me the methed of jquery to retrieve the element of array in txt file and to put the element of array to the corresponding “div” of html file. Thank you for harleydk’s help again!!! I have a very good webpag of heating system now (see picture 1 as follow). the 16 temperature(yellow color) run well in the webpage and the value of 16 temperature will be refreshed each 5 second.
I have also tried the method of AJAX XMLHttpRequest, I want to know, how the AJAX XMLHttpRequest works. In the picture 2, you can see a array in the above, the array is the content of txt file (data.txt), 16 temperature values are in the array and I can see that they are refreshed each 5 second. I can only retrieve the complete array of the txt file, but I don’t know how to put the 16 temperature-elements of array to the corresponding “div” of html file. Can you help me and give me some suggestion.
The codes of this picture-2-webpage is as follow:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function Ajax() {
var $http,$self = arguments.callee;
if (window.XMLHttpRequest) {
$http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
$http = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
$http = new ActiveXObject('Microsoft.XMLHTTP');
}
}
if ($http) {
$http.onreadystatechange = function () {
if (/4|^complete$/.test($http.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http.responseText;
setTimeout(function () { $self(); }, 5000);
}
};
$http.open('GET', 'data.txt', true);
$http.send(null);
}
}
</script>
</head>
<body>
<script type="text/javascript">
setTimeout(function () { Ajax(); }, 5000);
</script>
<div style="background:url(TYP400101_PNG.dat) no-repeat;width:1512px;height:794px">
<div id="ReloadThis">Default text</div>
</div>
</body>
</html>