Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: ResponseXML

  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    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 10:00 AM.

  • #2
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    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 :)

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Okay this is something I have already tried before. I still get a error back from JavaScript.

  • #4
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    As much as I would like to say that work, it did not. I'm still getting the same error.

  • #6
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    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.

  • #7
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I put that in my code and it isn't popping up with a error or anything. Not to sure why though.

  • #8
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    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.

  • #9
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    <?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.

  • #10
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    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.

  • #11
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    undefined

  • #12
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    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.

  • #13
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    The alert stays the same. undefined

  • #14
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    Do you have a link to the page?
    Software and cathedrals are much the same - first we build them, then we pray.

  • #15
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •