Hello, I've been trying to figure out this problem out for almost 3 hours now and I've looked all over the web and I can't really find any good tutorial help on this.
The following script works fine with request.responseText;
Code:
<html>
<head><title></title>
<script type="text/javascript" language="javascript">
var request;
function requestViews() {
try {
//takes care of all browser but IE
request = new XMLHttpRequest();
}catch(e) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e) {
alert("Your browser doesn't seem to support XMLHTTP");
}
}
}
request.onreadystatechange = function() {
if(request.readyState == 4) {
if (request.status == 200 || request.status == 304) {
var xmlDoc = request.responseXML;
document.getElementById('totalView').innerHTML = xmlDoc.getElementByTagName('views')[0].childNodes[0].nodeValue;
document.getElementById('short').innerHTML = xmlDoc.getElementByTagName('short')[0].childNodes[0].nodeValue;
}
else
{
var xmlDoc = request.responseXML;
document.getElementById('totalView').innerHTML = xmlDoc.getElementByTagName('views')[0].childNodes[0].nodeValue;
document.getElementById('short').innerHTML = xmlDoc.getElementByTagName('short')[0].childNodes[0].nodeValue;
}
}
else if (request.readyState <= 0) {
document.getElementById('totalViews').innerHTML = "<img src=\"/images/loader2.gif\" />";
}
}
var title = "How to install updates in Vista";
var queryString = "?title="+title;
request.open("GET", "serverTime.php"+queryString, true);
request.send(null);
setTimeout("requestViews()", 1000);
}
</script>
</head>
<body onload="requestViews();">
<div id="short"></div>
<div id="totalView"></div>
</body>
</html>
PHP CODE:
PHP Code:
<?php
header('Content-Type: text/xml');
//A date in the past
$title = $_GET['title'];
echo "<tutorial>";
echo "<views id=\"1\">".$title."</views>";
echo "<short id=\"2\">".$title."</short>";
echo "</tutorial>";
?>
But with responseXML I got a error message from IE and other browser don't display anything.
What am I doing wrong here?
Error Message:
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
Timestamp: Wed, 21 Oct 2009 07:53:16 UTC
Message: Object doesn't support this property or method
Line: 28
Char: 3
Code: 0
Message: Object doesn't support this property or method
Line: 28
Char: 3
Code: 0
Message: Object doesn't support this property or method
Line: 28
Char: 3
Code: 0