JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 22nd, 2006, 02:14 PM
dante2010 dante2010 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2002
Posts: 599 dante2010 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 3 h 46 m 49 sec
Reputation Power: 7
Prototype : Returning XML

Hi,

I am attempting to use the prototype framework in an application. I am using it's Ajax functions and would like to know how I get the XML that is returned from the Ajax request call. Any documentation I've seen only talks about using the "originalRequest.responseText" as a way to get what was returned. Is there not a way to get some sort of XML object returned from it?

My code is (if it helps):

Code:
function getControlID(type) {
	
	url = ssl + '/includes/ajax/getControlID.cfm';
	pars = 'type=' + type;
			
    myAjax = new Ajax.Request( url,
				 { method: 'get',
			         parameters: pars,
				 onComplete: addControl }); 

}

function addControl(originalRequest) {
	
	currentID = originalRequest.responseText;
	
	alert(currentID);
}


So right now all I'm getting back as an example is:

Code:
<?xml version="1.0" encoding="utf-8" ?> 
<ajax-response>
	<response type="object" id="controlDetails">
		<control>
			<nextID>2</nextid> 
			<type>text</type> 
		</control>
	</response>
</ajax-response>	


.. as plain text.

Reply With Quote
  #2  
Old August 22nd, 2006, 03:24 PM
oOo's Avatar
oOo oOo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 185 oOo User rank is Sergeant (500 - 2000 Reputation Level)oOo User rank is Sergeant (500 - 2000 Reputation Level)oOo User rank is Sergeant (500 - 2000 Reputation Level)oOo User rank is Sergeant (500 - 2000 Reputation Level)oOo User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 6 h 52 m 20 sec
Reputation Power: 15
You have to use 'responseXML' instead of 'responseText'. I'm not sure how Prototype handles it, though. You may need to send an xml header with the request if you have problems receiving it.

Reply With Quote
  #3  
Old October 5th, 2006, 09:30 AM
ajax's Avatar
ajax ajax is offline
Resident DJ
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 278 ajax User rank is Lance Corporal (50 - 100 Reputation Level)ajax User rank is Lance Corporal (50 - 100 Reputation Level)ajax User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 23 h 38 m 26 sec
Reputation Power: 8
Quote:
Originally Posted by oOo
You have to use 'responseXML' instead of 'responseText'. I'm not sure how Prototype handles it, though. You may need to send an xml header with the request if you have problems receiving it.


It doesn't handle it very well... You do have to send the header, but it does not help.

I'm having the same exact issue as the OP.

First the XML returned (submitting is no problem, reading is)

Code:
<?xml version="1.0" encoding="utf-8" ?>
<ajax-reponse>
  <response type="object" id="VenueDetailsId">
    <venue>
      <venue-id>9521</venue-id>
      <venue-name>Sneed's Feed & Seed (Formerly Chuck's)</venue-name>
    </venue>
  </response>
</ajax-reponse>


javascript Code:
Original - javascript Code
  1. <script type="text/javascript">
  2. function FormSubmit() {
  3.   var someNodeList = $('FormId').getElementsByTagName('input');
  4.   var nodes = $A(someNodeList);
  5.   var url = "/form.php";
  6.   var pars = "type=addvenue";
  7.   for(var i=0; i < nodes.length; i++) {
  8.     if("button" != nodes[i].type) {
  9.       pars += "&" + nodes[i].name + "=" + nodes[i].value;
  10.     }
  11.   }
  12.  
  13.  
  14.   var myAjax = new Ajax.Request(
  15.     url,
  16.     {
  17.       method: 'post',
  18.       parameters: pars,
  19.       onComplete: handlerFunc,
  20.       onFailure: reportError
  21.     });
  22. }
  23.  
  24. var handlerFunc = function(t) {
  25.   try {
  26.     var xmlDoc = t.responseXML.documentElement;
  27.     // returns HTML Object or HTML Collection
  28.     // and attempts to loop through return UNDEFINED or NULL
  29.  
  30.   } catch(e) {
  31.     alert(e.message);
  32.   } 
  33.     //Handle data.
  34. }
  35.  
  36.  
  37. </script>


Now, if I get out of using Prototype.js back to the w3schools example, it works just fine (but no more prototype, which is unfortunate because outside of this issue it works well and I've written some nice code to go along with it)

w3schools option - which works in comparison


But if I go back to the way a little more familiar (this is from w3schools.com) it works perfectly

Last edited by ajax : October 5th, 2006 at 09:33 AM.

Reply With Quote
  #4  
Old October 5th, 2006, 10:35 AM
ajax's Avatar
ajax ajax is offline
Resident DJ
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 278 ajax User rank is Lance Corporal (50 - 100 Reputation Level)ajax User rank is Lance Corporal (50 - 100 Reputation Level)ajax User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 23 h 38 m 26 sec
Reputation Power: 8
I figured it out.

Using "text/xml" doesn't work


This takes care of it:
PHP Code:
 header("Content-Type: application/xml; charset=utf-8"); 

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Prototype : Returning XML


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway