saravana kumar

saravana kumar

  • NA
  • 31
  • 45.9k

How to xml output from API using javascript?

Jul 25 2013 3:44 AM
This Is my API URL:

https://noc.iglass.net/LOGIN?credential_0=mohan.rao&credential_1=********&destination=%2Fjglass%2Fcpe%2FaccountCpeDataApi.do%3Fcust%3Datl-fl%26init%3D1%26account%3D8783200010007088

AND XMl OUTPUT is shown Below:

<accounts>

<account>

<id>8783200010007088</id>

<address>100 W SAN MARINO DR, MIAMI BEACH</address>

<node>MIA-58</node>

<cpes>

<cpe>

<mac>00:1d:d6:77:ac:89</mac>

<type>p</type>

<responder><font color="green">Online</font></responder>

<health><span class="green_text">RxPwr&nbsp;=&nbsp;3.5</span>, <span class="green_text">TxPwr&nbsp;=&nbsp;42.3</span>, <span class="green_text">UpSNR&nbsp;=&nbsp;35.1</span>, <span class="green_text">DwnSNR&nbsp;=&nbsp;35.2</span></health>

<flap>N/A</flap>

<bw><font color="green">Up=8.71MB Down=1.45MB</font></bw>

<battery><font color="green">Good</font></battery>

<device>ts-1-mia-(d50:0.11m)-(50:14)</device>

<custom-billing>

<Name>
                  DONALD ALTMAN
               </Name>

<Type>
                  M6
       </Type>

</custom-billing>

</cpe>

</cpes>

</account>

</accounts>

I want to hit this API From Javascript. from my XML Output Iwant to read Responder tag Innertext  "Online".

My Code is shown Below:

<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(id)
{
var xmlhttp;
var txt,x,i;
var url="https://noc.iglass.net/LOGIN?credential_0=mohan.rao&credential_1=5cm7U@Mw&destination=%2Fjglass%2Fcpe%2FaccountCpeDataApi.do%3Fcust%3Datl-fl%26init%3D1%26account%3D"+id;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    xmlDoc=xmlhttp.responseXML;
    txt="";
    x=xmlDoc.getElementsByTagName("responder");
    for (i=0;i<x.length;i++)
      {
      txt=txt + x[i].childNodes[0].nodeValue + "<br>";
      }
    document.getElementById("myDiv").innerHTML=txt;
    }
  }
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script>
</head>

<body>
<div id="myDiv"></div>
<input type="text" id="txtid" size="40"/>
<button type="button" onclick="loadXMLDoc(txtid.value)">Check Modem</button>
 
</body>
</html>

Here Am using one Textbox and one button when the button is clicking i want to pass textbox value into the API and then i want to show the status like "online" or "offline" from the responder TAG.

Now the problem is,

Am getting the needed outout from the above code but it is only working in "IE".API is not hitting properly in firefox and chrome.

How can i solve this problem or suugest me any other way to get output?

Answers (1)