No Limit
Party Escort Bot
- Joined
- Sep 14, 2003
- Messages
- 9,018
- Reaction score
- 1
Today at work I played around with controlling some embedded electronics using Javascript and LabVIEW. I got everything working using regular javascript which was awesome. I got to monitor a 20,000 watt power supply using a web browser.
Here is the code:
But I'm having a hard time finding code examples of doing this with the prototype framework. All I would like to do is read a simple XML request and add it to an array in the javascript.
At this point the XML file looks something like this:
Anyone got any advice or code examples of how I can take XML data and assign it to a javascript array using prototype? I've been lookihng around and can't find any samples to work from. I would appreciate the help.
Here is the code:
PHP:
<html>
<head>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc()
{
xmlhttp=null;
var url="../LambdaWeb/Lambda/read_volts";
if (window.XMLHttpRequest)
{// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}
function state_Change()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
var response_array = new Array();
var response = xmlhttp.responseText;
response_array = response.split('read_buffer');
var foramted_volts = response_array[1];
*************ElementById('T1').innerHTML=foramted_volts;
}
else
{
*************ElementById('T1').innerHTML=xmlhttp.statusText;
}
}
}
</script>
</head>
<body onload="loadXMLDoc(); setInterval('loadXMLDoc()', 1000 )" bgcolor="#000000">
<div id="T0">Volts:</div>
<div id="T1"></div>
<div ></div>
<div id="copyright">
<p>Sample TDK-Lambda Genesys Web 2.0 Program</p>
Program By: ****** @ *******</div>
</body>
</html>
But I'm having a hard time finding code examples of doing this with the prototype framework. All I would like to do is read a simple XML request and add it to an array in the javascript.
At this point the XML file looks something like this:
PHP:
<?xml version="1.0" encoding='UTF-8'?>
<data>
<read_volts>
10.001
</read_volts>
<read_current>
2.874
</read_current>
</data>
Anyone got any advice or code examples of how I can take XML data and assign it to a javascript array using prototype? I've been lookihng around and can't find any samples to work from. I would appreciate the help.