ajax problem parsing responseXML
Posted: Wed Aug 04, 2010 7:57 am
Hello, I am having a small problem parsing my response XML, here is the code I'm using and then I'll explain the problem.
my log of responseXML looks like this:
my log of responseText looks like this:
My problem is in handle_email(ajax), the line
throws an error:
The script almost works, but how am I supposed to parse it properly?
Thanks,
Shawn
Code: Select all
window.onload = function()
{
document.getElementById("email").addEventListener("keyup", verify_email, false);
}
function verify_email()
{
$params = "email=" + document.getElementById("email").value;
send_request("handle_email", "email", $params);
}
function handle_email(ajax)
{
var status = ajax.getElementsByTagName("status")[0].nodeValue;
}
function send_request(handler, processor, params, method)
{
if (!handler || !processor)
{
return;
}
if(!params)
{
params = "";
}
if(!method)
{
method = "POST";
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open(method, "ajax/" + processor + ".php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(params);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
console.log(xmlhttp.responseXML);
console.log(xmlhttp.responseText);
eval(handler + "('" + xmlhttp.responseXML.documentElement + "')");
}
}
}
Code: Select all
Document
<response>
<status>false</status>
<info>invalid email address</info>
</response>Code: Select all
<?xml version="1.0" encoding="UTF-16"?>
<response>
<status>false</status>
<info>invalid email address</info>
</response>Code: Select all
var status = ajax.getElementsByTagName("status")[0].nodeValue;Code: Select all
Uncaught TypeError: Object [object Element] has no method 'getElementsByTagName'Thanks,
Shawn