<link id = "StyleTag"
rel = "stylesheet"
type = "text/css"
href = ""
media = "all" />
<script type = "text/javascript">
if (navigator.userAgent.indexOf ("MSIE") != -1) LoadStyle (".../IE_Style.css");
else
{
if (navigator.appName.indexOf ("Netscape" != -1)) LoadStyle (".../NS_Style.css");
// etc...
}
function LoadStyle (StyleSheetName)
{
document.getElementById ("StyleTag").href = StyleSheetName;
}
</script>
function Handler ()
{
if (RequestObj.readyState == 4)
{
if (RequestObj.status == 200) // Do something here with
// RequestObj.responseText
// or RequestObj.responseXML
else throw ("Error");
}
}
var RequestObj;
if (window.XMLHttpRequest) RequestObj = new XMLHttpRequest ();
else if (window.ActiveXObject)
{
try { RequestObj = new ActiveXObject ("Msxml2.XMLHTTP"); }
catch (e)
{
try { RequestObj = new ActiveXObject ("Microsoft.XMLHTTP"); }
catch (e) { throw e; }
}
}
RequestObj.open (Method, URL, SyncFlag, ... );
RequestObj.onreadystatechange = Handler;
RequestObj.send (Data);
<!-- An invoice element in XML -->
<Invoice InvNum = "43508"
InvDate = "23/07/2005"
PONum = "53098">
<Item Desc = "Bolts" Num = "20" Price = "0.12" />
<Item Desc = "Washers" Num = "10" Price = "0.13" />
<Item Desc = "Screws" Num = "15" Price = "0.05" />
</Invoice>
// The same data encoded in JavaScript object-literal syntax
Invoice =
{
InvNum : "43508",
InvDate : "23/07/2005",
PONum : "53098",
Items : [ { Desc : "Bolts", Num : "20", Price : "0.12" },
{ Desc : "Washers", Num : "10", Price : "0.13" },
{ Desc : "Screws", Num : "15", Price : "0.05" } ]
}
var InvObj = eval("( { InvNum : '43508', InvDate : '23/07/2005' } )");
alert (InvObj.InvDate); // Displays 23/07/2005
<script type = "text/javascript">
var NumUsers_RequestObj = null;
var NumUsers_Elem = null;
function Init ()
{
NumUsers_Elem = document.getElementById ('NumUsers');
GetNumUsers ();
}
function GetNumUsers ()
{
try { NumUsers_RequestObj = IssueXHR ("POST",
".../NumUsers.php",
"",
true,
DisplayNumUsers); }
catch (e) { alert ("Error sending request - "
+ e.name
+ ": "
+ e.message); }
setTimeout ("GetNumUsers ()", 5000); // Triggers every 5 seconds
}
function DisplayNumUsers ()
{
if (NumUsers_RequestObj.readyState == 4)
{
if (NumUsers_RequestObj.status != 200) throw ("Error");
NumUsers_Elem.innerText = NumUsers_RequestObj.responseText;
}
}
function IssueXHR (Method, URL, Data, ASync, Handler)
{
// Code for creating XMLHTTPRequest, then opening and sending etc.
}
</script>
<body onload = "Init ()">
Users Logged on Currently = <span id = "NumUsers"></span>
</body>
var NumUsers_RequestObj = IssueXHR ("POST",
".../NumUsers.php",
"",
true,
DisplayNumUsers);
function IssueXHR (Method, URL, Data, ASync, ResponseHandler)
{
var XHRObj = ... // Code for creating XMLHTTPRequest object
XHRObj.open (Method, URL, ASync);
XHRObj.onreadystatechange = function ()
{
if (XHRObj.readyState == 4)
{
if (XHRObj.status == 200) ResponseHandler (XHRObj);
else throw ("Transaction complete but unsuccessful");
}
};
XHRObj.send (Data);
return XHRObj;
}
function DisplayNumUsers (XHRObj)
{
NumUsers_Elem.innerText = XHRObj.responseText;
}