Home > Domino Tips > Developer > Other > Using the XMLHTTP object for integration with Domino or any RDBMS back end
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

OTHER

Using the XMLHTTP object for integration with Domino or any RDBMS back end


vijay sreegiriraju
05.03.2005
Rating: -2.75- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


The XMLHTTP object allows one to open an HTTP connection to a server, send some data, and get some data back, all in a few lines of script. The data exchanged through the XMLHTTP object is usually XML, but it can also be in plain text or binary data. The binary data is particularly useful when uploading files.

The XMLHTTP object can be included on a Notes Form in the JS Header section as a function or directly in the onLoad event of the form. This can also be event driven, i.e., it can be inserted behind a button or image and invoked on click of the respective event handler.

To initialize the object, create a function, 
say 'loadXMLObj()' in the JSHeader of a form.

Function definition
 
function loadXMLObj()
{
 var xmlHttp = new ActiveXObject
("Microsoft.XMLHTTP") [Line1] for IE
 var xmlHttp = new XMLHttpRequest(); 
[Line1] for Netscape
 xmlHttp.open("GET", "/HTTPAgent?
openagent", false) [Line 2]
 xmlHttp.send() [Line 3]
 xmlStr=xmlHttp.responseText [Line 4]
} 

[Line 1] is the first step wherein you 
initialize the XML object. 
In [Line 2], an HTTP Request is 
sent to the server.
The server in the example above is
 the default Domino server.
The request is like an agent trigger. 
In [Line 3], the Request is sent to the server.
Finally in [Line 4] the Response is 
retrieved and it is in the form of plain text.

The response can be in the form of an
 XML object in which case you will use:

xmlDoc=xmlHttp.responseXML 
(The XMLDoc in this case is an XML object)

Some of the important properties 
that the XMLObject supports are 
listed below.
readyState – returns the 
loading state of the XMLHTTP object
reponseText – returns the
 request of the object either as a 
string,XML object or binary data
status – returns the status 
of the operation as a code
statusText – return the status
 of the operation as a string

The above properties of the XMLHTTP 
object are particularly useful in order
 to determine
whether the connection to the remote 
server was established successfully or not.

Finally in the onLoad event of the form, 
include the function call 'loadXMLObj()'


Now let us proceed to the agent.


Agent Header

In the beginning of the agent, include 
the following statement:

Print "Content-Type:text/plain"
[Note: This is used if the response 
must be a string]

(or)

Print "Content-Type:text/xml"
[Note: This is used if the response 
must be in XML format]   


Agent Body

Here you may include native agent code like-

Dim session as new notessession
Dim db as notesdatabase
…….
[Proceed to initialize all required 
doc handles] ……..


Let us say the requirement is to return 
a field value from a collection of documents.

While not doc is nothing
Print doc.FieldName(0) [Response statement]
 Set doc = DocColl.getNextDocument(doc) Wend


The line marked in Bold is the key command 
wherein the agent 'Response' is sent to the 
XMLHTTP Object.
This is done using the Print statement.

That's all there is to it. How the agent can be used is left to the Business Requirement.
You can connect to an RDBMS, any third-party application and send the response to the client without page refresh.
The response time is also much faster compared to CGI methods.
Besides agents, you can also use this object to load an XML file and traverse the tree using the XMLDOM.

To use this as a substitute for a 
@Dblookup, you can send the request 
as a 'readviewentries' view command
and the response can be obtained 
in the form of a string.

For example:

var xmlHttp = 
new ActiveXObject("Microsoft.XMLHTTP")
xmlHttp.open("GET", "/SampleView?
readviewentries&startkey=keyvalue", 
false)  [Sorted view]
xmlHttp.open("GET", "/SampleView?
readviewentries&restricttocategory=category", 
false)  [Categorized view]
xmlHttp.send()
xmlStr=xmlHttp.responseText

Do you have comments on this tip? Let us know.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Other
Create a dynamic user-driven navigator for a Notes/Domino application
How to apply XSL style sheets to XML views
Comparing replicas on clustered Lotus Domino servers
Creating a Lotus Notes view column categorized by month
Hiding field properties/data from DocProperties box
Export a view to Excel without coding
Prevent document deletion if there are response documents
Switching between test IDs quickly
AddParameter to a NotesXSLTransFormer
Using DXL (Domino XML) to review/modify documents

XML and Web Services for Lotus Notes Domino
Create an RSS feed in Notes/Domino 8 with XML
Verify scheduled agent status with Domino Extensible Language (DXL)
Top 10 Lotus Notes Domino programming and development tips of 2007
A bevy of Notes/Domino development tips
Loading XML from JavaScript
How to apply XSL style sheets to XML views
Top 10 Notes/Domino developer tips of 2006
A smorgasbord of Notes/Domino development tips
Converting XML files into Lotus Notes documents
Finding the properties of a doclinked Lotus Notes document

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts