wrong syntax in IE? - ajax & Js
i have a code line like this: (JS)
numOfprocess = parseInt(xmlDoc.getElementsByTagName('process_count')[0].childNodes[0].nodeValue)
for (i = 1; i <= numOfProcess; i++)
{
processStatus = xmlDoc.getElementsByTagName('proccess' + i)[0];
if(processStatus.childNodes[0].nodeValue == false)
{...}
}
everytime i use this syntax there is an error "obejct required" while in Firefox eveything is ok. (the ... are just to explain)
i tried to do some debug like this:
alert(processStatus.childNodes[0].nodeValue)
and the result was 0 so the var is fine. (also worked in ff so..)
the x开发者_如何学编程ml:
<process_count>2</process_count>
<Application_Status>
<proccess2>1</proccess2>
</Application_Status>
another thing is that for i=1 it's ok but for i=2 not.
Thank you.
Indexing starts from 0, so if you have three items, their corresponding indexes are 0
, 1
and 2
, so you need to loop:
for (i = 1; i < numOfProcess; i++)
instead of:
for (i = 0; i <= numOfProcess; i++)
EDIT:
You don't need a for loop to access your data, you can easily access required value via:
var processId = xmlDoc.getElementsByTagName('process_count')[0].childNodes[0].nodeValue;
var processStatus = xmlDoc.getElementsByTagName('process'+processId)[0].childNodes[0].nodeValue;
But, I suggest reconsidering your xml schema, since you need no more than one process status, why not doing simple thing like:
<application>
<process id="2" status="1" />
</application>
精彩评论