Solved

refresh XML content with ASP

Posted on 2013-05-20
4
659 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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, …
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 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