Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 668
  • Last Modified:

refresh XML content with ASP

Hello experts,

It's been quite a while since I worked with ASP and XML and I am struggling to remember the simplest operations I used to do very easily.

Here is what I want to do:

I have an XML document and I want to display it with ASP without any change. (For example my test.asp will display exactly my test.xml)

The trick is I want this ASP page to refresh every 15 seconds and bring the latest XML document content. I was able to do that previously with:
   Response.AddHeader("Refresh",Head)

Can you share a sample code please? I don't have much time.

Thank you in advance
0
bozer
Asked:
bozer
  • 2
  • 2
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
You can set a timer with vb but it eats up the cpu.  I would just use js like below.  If you want to get fancy, then jquery/ajax or js/ajax

<html>
<head>
<script type="text/JavaScript">
<!--
function AutoRefresh( t ) {
	setTimeout("location.reload(true);", t);
}
//   -->
</script>
</head>
<body onload="JavaScript:AutoRefresh(5000);">
<p>This page will refresh every 5 seconds.</p>
</body>
</html>

Open in new window

0
 
bozerAuthor Commented:
Thank you Padas,

Can you please share how to add the XML content ? My main issue is I am rusty with the methodology of doing that.
0
 
Scott Fell, EE MVEDeveloperCommented:
One way is xmlhttp post http://support.microsoft.com/kb/290591
<%
	DataToSend = "id=1"
	dim xmlhttp 
	set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
	xmlhttp.Open "POST","http://localhost/Receiver.asp",false
	xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	xmlhttp.send DataToSend
	Response.ContentType = "text/xml"
	Response.Write xmlhttp.responsexml.xml
        Set xmlhttp = nothing
%>

Open in new window


Or pure ajax
http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
}
xmlhttp.open("GET","demo_get.asp",true);
xmlhttp.send();
}
</script>
</head>
<body>

<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<div id="myDiv"></div>

</body>
</html>

Open in new window


or jquery  http://api.jquery.com/jQuery.ajax/

<script>

$.ajax({
  url: "test.xml",
  cache: false
}).done(function( xml ) {
  $("#results").append(xml);
});
</script>

<div id="results"></div>

Open in new window

0
 
bozerAuthor Commented:
Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now