Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-21-2009, 08:55 AM   PM User | #1
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
ResponseXML

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

Last edited by Jon W; 10-21-2009 at 09:00 AM..
Jon W is offline   Reply With Quote
Old 10-21-2009, 01:08 PM   PM User | #2
barkermn01
Regular Coder

 
Join Date: Nov 2007
Location: Leeds, UK
Posts: 514
Thanks: 24
Thanked 19 Times in 19 Posts
barkermn01 can only hope to improve
Your Not Telling AJAX its an XML File you missing the XML Header go lookup on XML Standards,

echo "<?xml version="1.0" encoding="iso-8859-1"?>";

and make sure you echo it coz that header in php buggs if short tags are allowed
__________________
Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)
barkermn01 is offline   Reply With Quote
Old 10-21-2009, 06:19 PM   PM User | #3
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
Okay this is something I have already tried before. I still get a error back from JavaScript.
Jon W is offline   Reply With Quote
Old 10-21-2009, 06:22 PM   PM User | #4
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
There is a typing mistake.
You should replace:
Code:
getElementByTagName
with
Code:
getElementsByTagName
__________________
Software and cathedrals are much the same - first we build them, then we pray.
ckeyrouz is offline   Reply With Quote
Old 10-21-2009, 07:10 PM   PM User | #5
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
As much as I would like to say that work, it did not. I'm still getting the same error.
Jon W is offline   Reply With Quote
Old 10-21-2009, 07:15 PM   PM User | #6
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
Can you please insert these two lines:
Code:
alert(request.parseError.reason)
alert(request.parseError.srcText)
Directly after this line:
Code:
if(request.readyState == 4) {
And send me back the result of the alert messages.
__________________
Software and cathedrals are much the same - first we build them, then we pray.
ckeyrouz is offline   Reply With Quote
Old 10-21-2009, 07:30 PM   PM User | #7
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
I put that in my code and it isn't popping up with a error or anything. Not to sure why though.
Jon W is offline   Reply With Quote
Old 10-21-2009, 07:34 PM   PM User | #8
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
No problem for that this is specific for IE I think and it does not work on other browsers anyway replace the code that I have posted in the previous reply with the following;
Code:
alert(request.responseText);
And feed me back with the result, please.
__________________
Software and cathedrals are much the same - first we build them, then we pray.
ckeyrouz is offline   Reply With Quote
Old 10-21-2009, 07:45 PM   PM User | #9
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
<?xml version="1.0"?><tutorial><views>164</views><short>There is some updates that you will have to make sure that you install. So if you are unsure how to do this then this tutorial will explain step by step how to do that.</short></tutorial>

XML is coming out fine. I just simply don't get it.
Jon W is offline   Reply With Quote
Old 10-21-2009, 07:51 PM   PM User | #10
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
ok now would you try this:
Code:
alert(request.responseXML.xml)
__________________
Software and cathedrals are much the same - first we build them, then we pray.
ckeyrouz is offline   Reply With Quote
Old 10-21-2009, 07:54 PM   PM User | #11
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
undefined
Jon W is offline   Reply With Quote
Old 10-21-2009, 07:57 PM   PM User | #12
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
try adding the CDATA section to the short tag as follows:
Code:
echo "<short id=\"2\"><![CDATA[".$title."]]></short>";
__________________
Software and cathedrals are much the same - first we build them, then we pray.
ckeyrouz is offline   Reply With Quote
Old 10-21-2009, 08:01 PM   PM User | #13
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
The alert stays the same. undefined
Jon W is offline   Reply With Quote
Old 10-21-2009, 08:04 PM   PM User | #14
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
Do you have a link to the page?
__________________
Software and cathedrals are much the same - first we build them, then we pray.
ckeyrouz is offline   Reply With Quote
Old 10-21-2009, 08:05 PM   PM User | #15
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
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) {
				alert(request.responseText);
				if (request.status == 200 || request.status == 304) {
				
					var xmlDoc = request.responseXML;
		document.getElementById('totalView').innerHTML = xmlDoc.getElementsByTagName('views')[0].childNodes[0].nodeValue;
		document.getElementById('short').innerHTML = xmlDoc.getElementsByTagName('short')[0].childNodes[0].nodeValue;
					
					
				}
				else
				
				{
					var xmlDoc = request.responseXML;
		document.getElementById('totalView').innerHTML = xmlDoc.getElementsByTagName('views')[0].childNodes[0].nodeValue;
		document.getElementById('short').innerHTML = xmlDoc.getElementsByTagName('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);
	
		
	}
</script>
</head>
<body onload="requestViews();">
<div id="short"></div>
<div id="totalView"></div>
</body>
</html>
Not to sure what exactly happened but this seems to be working now.
Jon W is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:47 PM.


Advertisement
Log in to turn off these ads.