Example of how to call a .net webservice via javascript on a timed delay

J

Josh Harris

You can copy and paste the following into a .aspx page (change names
for your purpose) and it will call a webservice on every 1 minute. I
used this piece of code for the purpose of refreshing a datagrid
without having to make a postback to the server.

<script language="javascript">

function startRefreshDelay() {
UpdateGrid();
timer = setTimeout("startRefreshDelay()",60000);
}


function UpdateGrid()
{

var xmlObj = new ActiveXObject("Msxml2.DOMDocument");
var sXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
sXml += "<soap:Envelope "
sXml += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
";
sXml += "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ";
sXml += "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
sXml += "<soap:Body>";
sXml += "<GetDailyRetailKPI xmlns=\"http://www.tempuri.org/\">";
sXml += "<strXML><testnode>test</testnode></strXML>";
sXml += "</GetDailyRetailKPI></soap:Body></soap:Envelope>";

// Try to parse the XML string into DOM object
xmlObj.loadXML(sXml);

var xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
xmlHTTP.Open ("Post", "http://eis/GridXML/GridXML.asmx", false);
xmlHTTP.setRequestHeader("SOAPAction",
"http://tempuri.org/GetDailyRetailKPI");
xmlHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8"
);
xmlHTTP.Send(sXml);

var xmlResponse = xmlHTTP.responseXML ;
DailyRetailKPI.innerHTML =
xmlResponse.selectSingleNode("soap:Envelope/soap:Body").text ;
}
</script>
 
Joined
Jul 30, 2008
Messages
1
Reaction score
0
Excellent Simple Script

Josh,

I have registered to this site after seeing your above post and it is a jam.

Regards,
Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top