比较用ajax两个XML值 [英] Compare two xml values using ajax
问题描述
好了,我想监视和控制的东西与PIC-网络的芯片。我设法给它编程所有除了一件事。我需要比较两个温度,它给我,如果其中有一个是小的,其他则中继需要被激活,如果其大于等于然后另一中继必须被激活。从我的理解PIC-网站更新的XML文件(status.xml),那么网站(使用AJAX)从那里取值,并在网页上显示它们。
XML文件看起来像这样
<响应>
< TEMP0>〜温度〜< / TEMP0>
< TEMP2>〜tempc〜< / TEMP2>
< /响应
阿贾克斯code我用它来得到我的网页的值
的document.getElementById('TEMP0)的innerHTML = getXMLValue(XMLDATA,TEMP0)。
的document.getElementById('TEMP2)的innerHTML = getXMLValue(XMLDATA,TEMP2)。
和显示他们,我用
<跨度ID =TEMP0的风格=字体重量:正常?>< / SPAN>
<跨度ID =TEMP2的风格=字体重量:正常?>< / SPAN>
所有我需要做的是比较TEMP0与TEMP2
VAR TEMP0 = parseFloat(的document.getElementById('TEMP0')。innerHTML的)
VAR TEMP2 = parseFloat(的document.getElementById('TEMP2')。innerHTML的)
如果(TEMP0< TEMP2)
{
的document.getElementById('TEMP3)的innerHTML ='<字体颜色=#00FF00>在< / FONT>';
}
其他
{
的document.getElementById('TEMP3)的innerHTML ='<字体颜色=#00FFFF>关闭< / FONT>';
}
在我刚加入<跨度ID =TEMP3>< / SPAN>
来显示结果。
我是正确的?
如果(getXMLValue(XMLDATA,TEMP0')其中,TEMP2)
TEMP0
不是的document.getElementById的值('TEMP0')
,它只是一个字符串你做了包含TEMP0。
您需要分配这一个变量,它从一个字符串转换成一个数字:
VAR TEMP0 = parseFloat(的document.getElementById('TEMP0')。innerHTML的)
VAR TEMP2 = parseFloat(的document.getElementById('TEMP2')。innerHTML的)
然后使用:
如果(TEMP0< TEMP2)
OK, so I'm trying to monitor and control something with a Pic-web from microchip. I managed to program it all except for one thing. I need to compare two temperatures that it gives me, and if one of them is smaller that the other then a relay needs to be activated, if its bigger or equal then another relay must be activated. From what I understood Pic-web updates an xml file (status.xml) then the website (using ajax) takes the values from there and displays them on the web page.
The XML file looks like this
<response>
<temp0>~temp~</temp0>
<temp2>~tempc~</temp2>
</response
The ajax code I use to get the values in my web page
document.getElementById('temp0').innerHTML = getXMLValue(xmlData, 'temp0');
document.getElementById('temp2').innerHTML = getXMLValue(xmlData, 'temp2');
And to display them I use
<span id="temp0"style="font-weight:normal">?</span>
<span id="temp2"style="font-weight:normal">?</span>
All I need to do is to compare temp0 with temp2
var temp0 = parseFloat(document.getElementById('temp0').innerHTML)
var temp2 = parseFloat(document.getElementById('temp2').innerHTML)
if( temp0 < temp2 )
{
document.getElementById('temp3').innerHTML = '<font color="#00FF00">ON</font>';
}
else
{
document.getElementById('temp3').innerHTML = '<font color="#00FFFF">OFF</font>';
}
The I just add <span id="temp3">?</span>
to display the result
Am I correct?
if(getXMLValue(xmlData, 'temp0') < 'temp2')
'temp0'
is not the value of document.getElementById('temp0')
, it's just a string you made up containing 'temp0'.
You need to assign this to a variable and convert it to a number from a string:
var temp0 = parseFloat(document.getElementById('temp0').innerHTML)
var temp2 = parseFloat(document.getElementById('temp2').innerHTML)
Then use:
if(temp0 < temp2)
这篇关于比较用ajax两个XML值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!