Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DJJD.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="JavaScript" src="MyAJAX.js"></script>
<script type="text/javascript" language="JavaScript">
window.onload = function () {
GetMyData();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="MyDiv">
<br />
</div>
</div>
</form>
</body>
</html>
var XmlHttp; //Object which retrieves data from server
var MyDataDBID = new Array(); //List of received Database ID's
var MyDataCaption = new Array(); //List of received Captions
function GetMyData() {
//Identify type of browser and handle accordingly
if (window.XMLHttpRequest) // code for IE7+, Firefox, Chrome, Opera, Safari
{
XmlHttp = new XMLHttpRequest();
}
else // code for IE6, IE5
{
XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
//Assign response method
XmlHttp.onreadystatechange = ReceiveMyData;
//Open and send request to server
XmlHttp.open("GET", "/Command.aspx?CMD=GETDATA", true);
XmlHttp.send();
}
function ReceiveMyData() {
//Check if data is ready, if so, continue to reading the data
if (XmlHttp.readyState == 4 && XmlHttp.status == 200) {
var xmlDoc = XmlHttp.responseXML; //Get xml data from response
var x; //Temporary object to hold xml sub-data
var NewCount = 0; //Temporary variable - how many new records are in XML
//Don't read if nothing exists
if (xmlDoc != null) {
x = xmlDoc.getElementsByTagName("ID"); //Get list of all instances of the database id, or 'ID' from XML data
NewCount = x.length; //Set new count to number of new records
if (NewCount > 0) {
//Loop through all instances of 'ID'
for (i = 0; i < NewCount; i++) {
MyDataDBID[i] = x[i].childNodes[0].nodeValue; //Assign DBID array value
}
//Get list of all instances of 'Caption' from XML data
x = xmlDoc.getElementsByTagName("Caption");
//Loop through all instances of 'Caption'
for (i = 0; i < NewCount; i++) {
NewCaption[i] = DecodeString(x[i].childNodes[0].nodeValue);
}
//Loop through all new records and create HTML for each
var R = "<div style=\"width: 100%;\">"; //Temporary HTML code
for (i = 0; i < NewCount; i++) {
R += "<div style=\"width: 100%; text-align: center; border: 1px solid;\">";
R += "DBID: " + MyDataDBID[i] + " | Caption: " + MyDataCaption[i];
R += "</div>";
}
R += "</div>";
//Replace contents of 'MyDiv' with new HTML data
document.getElementById("MyDiv").innerHTML = R;
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Command.aspx.cs" Inherits="DJJD.Command" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Xml;
namespace DJJD
{
public partial class Command : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string Cmd = Request.QueryString["CMD"].ToString();
if (Cmd == "GETDATA")
{
using (MemoryStream S = new MemoryStream())
{
XmlTextWriter XmlDoc = new XmlTextWriter(S, System.Text.Encoding.ASCII);
//Start the document
XmlDoc.WriteStartDocument();
XmlDoc.WriteStartElement("Items");
//You would put a loop here adding the XML data record by record
//Instead, I will create the records manually for this example
var X = 1;
XmlDoc.WriteStartElement("Item");
XmlDoc.WriteElementString("ID", X.ToString());
XmlDoc.WriteElementString("Caption", "This is the first record");
XmlDoc.WriteEndElement();
X = 2;
XmlDoc.WriteStartElement("Item");
XmlDoc.WriteElementString("ID", X.ToString());
XmlDoc.WriteElementString("Caption", "This is the second record");
XmlDoc.WriteEndElement();
X = 3;
XmlDoc.WriteStartElement("Item");
XmlDoc.WriteElementString("ID", X.ToString());
XmlDoc.WriteElementString("Caption", "This is the third record");
XmlDoc.WriteEndElement();
//End the document
XmlDoc.WriteEndElement();
XmlDoc.WriteEndDocument();
XmlDoc.Flush();
//Prepare the response
byte[] Data = S.ToArray();
Response.Clear();
Response.AppendHeader("Content-Disposition", "filename=MyAJAXTest.xml");
Response.AppendHeader("Content-Length", Data.Length.ToString());
Response.ContentType = "text/xml";
//Send the response
Response.BinaryWrite(Data);
XmlDoc.Close();
}
}
}
}
}