Solved

refresh XML content with ASP

Posted on 2013-05-20
4
653 Views
Last Modified: 2013-05-21
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
Comment
Question by:bozer
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39183338
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
 

Author Comment

by:bozer
ID: 39183373
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
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 150 total points
ID: 39183410
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
 

Author Closing Comment

by:bozer
ID: 39183582
Thanks
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now