Imtiaz Abbas Imtiaz Abbas - 7 months ago 12
Javascript Question

Unable to get exact data from XML into JavaScript

I am just trying to alert the email from the XML but I am getting this as an alert.


▛▛email1@mail.com ▛


Help me in removing these box symbols. I actually wanted to validate the email, but I couldn't do that because the value returned contains these symbols.

JavaScript:

function process(){
if(xmlhttp.readyState == 4 || xmlhttp.readyState == 0){
xmlhttp.open("GET", "../text/info.xml", true);
xmlhttp.onreadystatechange = responseServer;
xmlhttp.send();
} else {
setTimeout("process()", 1500);
}
}

function responseServer(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
docxml = xmlhttp.responseXML;
emails = docxml.getElementsByTagName('email');
alert(emails[0].firstChild.nodeValue);
}
}

Answer

Replace

alert( emails[0].firstChild.nodeValue );

with

alert( emails[0].firstChild.textContent );