29 Jun 2007

How to read XML File From Server using javascript

This is a javascript that will read an XML File from Server and then check the content of xml file.
If XML file has been changed then page will be refreshed.Otherwise no postback or pagerefresh.


Specify Script tag and then write below javascript

function loadXMLDoc(dname)
{
var xmlDoc;
// code for IE if (window.ActiveXObject)
{ xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{ xmlDoc=document.implementation.createDocument("","",null); }
else { alert('Your browser cannot handle this script'); }
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}


function AddTimerForFunction(funcname,tsec)
{
tsec = 60*60; TFunc= t=setTimeout(funcname,tsec)
}

function RemoveTimerforFunction()
{
clearTimeout(TFunc);
}


var TFunc;
function LdFlashFrame()
{

xmlDoc=loadXMLDoc("<%=Str_FilePath%>");
var x=xmlDoc.getElementsByTagName('SheetNo');
for (i=0;i<=x.length;i++)
{

mySheet = x[i].childNodes[0].nodeValue;
//alert(myimg + top.reloadlock);
if ( top.reloadlock != mySheet )
{
top.reloadlock =mySheet;
top.mainFrame.location.reload();
break;
}
}

1 comment:

Anonymous said...

In the code nothing is useful to read the xml file from server. U are telling that loadXmLdOC where i have to specify the document nothing
It is an useless post please dont act as too smart i am wasting these kind of rubbish things sorry my frnd i am totally disappointed