You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

 
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)

Unknown macro: {        alert('Cannot create XMLHTTP instance');        return false;    }

   
    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

Unknown macro: {        // Firefox, Opera 8.0+, Safari        xmlHttp = new XMLHttpRequest();    }

    catch(e) {
        // Internet Explorer
        try

Unknown macro: {            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");        }

        catch(e)

Unknown macro: {            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");        }

    }
    return xmlHttp;
}

function pageUpdate() {
    if (http_request.readyState == 0)

Unknown macro: {        document.getElementById('resultbox').innerHTML = "Sending Request...";    }

    if (http_request.readyState == 1)

Unknown macro: {        document.getElementById('resultbox').innerHTML = "Loading Response...";    }

    if (http_request.readyState == 2)

Unknown macro: {        document.getElementById('resultbox').innerHTML = "Response Loaded...";    }

    if (http_request.readyState == 3)

Unknown macro: {        document.getElementById('resultbox').innerHTML = "Response Ready...";    }

    if (http_request.readyState == 4)

Unknown macro: {        //alert(http_request.responseText);        //addText (http_request.responseText);        loadXML (http_request.responseText);               http_request.open('GET', "http}

   
}

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
   

Unknown macro: {        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");        xmlDoc.async="false";        xmlDoc.loadXML(text);    }

    catch(e)
    {
        try //Firefox, Mozilla, Opera, etc.
       

Unknown macro: {            parser=new DOMParser();            xmlDoc=parser.parseFromString(text,"text/xml");        }

        catch(e)

Unknown macro: {alert(e.message)}

    }
    try
   

Unknown macro: {        var sResult = xmlDoc.documentElement.transformNode(xslDoc);        //alert (sResult);        addText (sResult);    }

    catch(e)

Unknown macro: {        alert(e.message)    }

   
}

function xslTest () {
try //Internet Explorer
{
    xslDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
    try //Firefox, Mozilla, Opera, etc.
   

Unknown macro: {        xslDoc=document.implementation.createDocument("","",null);    }

    catch(e)

}
try
{
    xslDoc.async=false;
    xslDoc.load("d:/temp/esme.xsl");
}
catch(e)

Unknown macro: {alert(e.message)}

}

</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>

  • No labels