I'm new with AJAX and I'm having trouble getting the data out of the XML. I'm getting the string "undefined" instead of the values I expect. I'm using the FireBug extension in Firefox to see the XML response and I can verify that all of the data is there. I must just be accessing it incorrectly.
Can someone take a look and suggest what I might be doing wrong?
Here's some of my JavaScript:
Here's the XML string from the response (formatted for easier reading). I can change the method to "GET" and get the same data by typing the URL in directly ...
Thank you,
--
-- Ghodmode
Give a man a fish and he'll come back to buy more... Teach a man to fish and you're out of business.
Can someone take a look and suggest what I might be doing wrong?
Here's some of my JavaScript:
Code:
function getResults( type ) {
var url = "getUserData.php";
var post_data = "user_id=" + user_id;
initRequest();
req.onreadystatechange = processRequest;
req.open( "POST", url, true );
req.setRequestHeader( "Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL] );
req.send( post_data );
} // End getResults function
function processRequest() {
if ( req.readyState == 4 ) {
if ( req.status == 200 ) {
response = req.responseXML.documentElement; // root element
method = response.childNodes[0].firstChild.data;
// This idea stolen from
// [URL unfurl="true"]http://www.xml.com/pub/a/2005/02/09/xml-http-request.html[/URL]
eval( method + '()' );
// The problem I'm having only occurs when the method
// is "updateData"
}
}
}
// ...
function updateData() {
var response_length = response.childNodes.length;
var data = '<table cellpadding="0" cellspacing="0" border="0">';
// Start at 1. 0 is the method
for ( i = 1; i < response_length; i++ ) {
var field = response.childNodes[i];
data += "<tr>";
data += "<td>";
data += field.tagName;
data += "</td>";
data += "<td>";
// Here's where the problem must be
data += field.data;
// And some other methods I've tried ...
//data += field.text;
//data += field.firstChild.data;
//data += field.firstChild.text;
data += "</td>";
data += "</tr>";
}
data += "</table>";
dataObj.innerHTML = data;
} // End updateData function
Here's the XML string from the response (formatted for easier reading). I can change the method to "GET" and get the same data by typing the URL in directly ...
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<user_data>
<method>updateData</method>
<user_id>Ghodmode</user_id>
<email>obfu@skated.com</email>
<fullname>Vincente Aggrippino</fullname>
<address></address>
<tel1></tel1>
<tel2></tel2>
<website></website>
<confirmed>0</confirmed>
<location>localhost</location>
<http_user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060614 Fedora/1.5.0.4-1.2.fc5 Firefox/1.5.0.4 pango-text</http_user_agent>
<remote_host></remote_host>
<remote_addr>127.0.0.1</remote_addr>
<os>Linux</os>
<browser>Mozilla Firefox</browser>
<remember_me>1</remember_me>
</user_data>
Thank you,
--
-- Ghodmode
Give a man a fish and he'll come back to buy more... Teach a man to fish and you're out of business.