Javascript Client - just messages
Html page
<script type="text/javascript" language="javascript">
var http_request = false;
var xslDoc = false;
function getFirstRequest() {
//Load XSL File
xslTest();
http_request = GetXmlHttpObject();
if (!http_request)
login();
getMessages ("http://api.esme.us/esme/api/get_msgs")
}
function login () {
var url = "http://api.esme.us/esme/api/login";
var params = "token="+encodeURIComponent("NSCPIKQ0QZ0GO2PJXMXGTKRL1O");
http_request.open("POST", url, false);
//Send the proper header information along with the request
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", params.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(params);
}
function getMessages(rest_type) {
http_request.open('GET', rest_type, true);
http_request.onreadystatechange = pageUpdate;
http_request.send(null);
}
function getNextRequest() {
http_request = GetXmlHttpObject();
if (!http_request)
login();
getMessages ("http://api.esme.us/esme/api/wait_for_msgs")
}
function GetXmlHttpObject() {
var xmlHttp = null;
try
catch(e) {
// Internet Explorer
try
catch(e)
}
return xmlHttp;
}
function pageUpdate() {
if (http_request.readyState == 0)
if (http_request.readyState == 1)
if (http_request.readyState == 2)
if (http_request.readyState == 3)
if (http_request.readyState == 4)
}
function addText (text) {
var pTag = document.createElement("p");
pTag.setAttribute("align","center");
pTag.innerHTML = text;
var div = document.getElementById("details")
div.insertBefore(pTag, div.childNodes[0]);
}
function loadXML (text) {
try //Internet Explorer
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
catch(e)
}
try
catch(e)
}
function xslTest () {
try //Internet Explorer
{
xslDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
catch(e)
}
try
{
xslDoc.async=false;
xslDoc.load("d:/temp/esme.xsl");
}
catch(e)
}
</script>
<body onload="getFirstRequest()">
<div id="resultbox"></div>
<div id="details"><p> </p></div>
</body>
XLS File
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="author">
<tr>
<td>
<img>
<xsl:attribute name="src"><xsl:value-of select="@image" /></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="@name" /></xsl:attribute>
</img>
From: <xsl:value-of select="@name" />
</td>
</tr>
</xsl:template>
<xsl:template match="body">
<tr><td>
Message: <xsl:value-of select="."/></td></tr>
</xsl:template>
<xsl:template match="esme_api">
<table>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>