XML Server Getting Started
Accessing server side objects from the client code with XML over HTTP calls
XMLSP technology enables developers to implement a great deal of presentation specific code within the browser without
overwhelming the server with the straight GUI related tasks. However, when it comes to server specific tasks, be that an
implementation of business rules that should not be exposed to the users for security reasons, or be that a file access which is
technically impossible from within the browser's sandbox there is a need to access server side objects from the JavaScript
code.
The
XMLHTTPRequest()
method of
xmlapi
object (/xmlsp/htc/xmlapi.htc) facilitates direct HTTP request from your client
side JavaScript to any URL. In a very schematic way of explaining things, it enables you to invoke your own JSP, servlet or
ASP page simply as a remote function taking parameters and returning values:
xmlOutObj = xmlapi.XM LHTTPRequest(url,[ xmInObj[, encoding]])
Internally
XMLHTTPRequest()
is a convenience method built on top of
IXMLHTTPRequest interface
.
XMLHTTPRequest()
requires one argument URL to invoke on the Application Server side. Optionally you may submit
XML object or string containing well formed XML as parameters envelope to be parse by the URL. The third optional
argument is the encoding of the parameters' data, which defaults to utf 8 .
XMLHTTPRequest()
expects URL to return
results as a well formed XML stream. The method may throw exceptions if it fails opening socket to specified URL or if the
URL times out or returns a non well formed XML.
XMLHTTPRequest()
executes synchronously: the first statement after
XMHTTPRequest()
is not executed until a response from URL has been processed.
The return value of
XMLHTTPRequest()
is the
XMLObject
containing well formed XML returned by the URL. The whole
idea of using JSPs or ASPs as simply for the purposes of fetching data is a major departure from the way people typically
think of URLs. Unlike regular Server Pages , JSPs or ASPs called via
XMLHTTPRequest()
are not returning HTML to be
rendered, but raw XML data to be processed by application logic on the client.
As an example, let's assume you designed a logon screen which contains input elements
userID
and
password
along
with buttons OK and Cancel (
/Examples/Tutorial/step5.jsp
):
UserID:
Password:
The following script, which, according to our practice we place right after closing
tag validates the user via
/Examples/Tutorial/EchoLogon.jsp :