Home > Domino Tips > Developer > JavaScript > Using Ajax as a replacement for @DBLookups
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVASCRIPT

Using Ajax as a replacement for @DBLookups


Sean Burgess
08.02.2005
Rating: -3.29- (out of 5)


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


We have started implementing Ajax (Asynchronous JavaScript and XML) in a number of applications at my company. Most of what we have done has been using agents to bring back HTML to change a Web page using

VIEW MEMBER FEEDBACK TO THIS TIP

the .innerHTML property. But I was thinking that I could just as easily bring back the same information I can get in an @DBLookup. The approach I took is very specialized, but can be expanded to pull back any information you would ever want.

Basically, I have a contact name field and a contact phone number field on the form in question. I want the contact phone field to be automatically populated from data in the person document. So I have the onBlur event for the contact name field set to getContactPhone(document.forms[0].contact.value,'contact_phone'); so that the contact's phone number is looked up in the Public Address Book whenever the user tabs out of the field.

The agent I created, GetOfficePhone, returns the user's phone number I want with two print statements:

Print "Content-type: text/plain"
Print doc.OfficePhoneNumber(0)

This technique could definitely be expanded to do full blown @DbColumn and @DBLookup functions. The JavaScript is as follows:

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject
("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject
("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 
'undefined') {
  xmlhttp = new XMLHttpRequest();
}

function getContactPhone(username, objID) {
  var obj = document.getElementById(objID);
  xmlhttp.open("GET", 
"/names.nsf/GetOfficePhone?
OpenAgent&username=" 
+ username);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 
4 && xmlhttp.status == 200) {
      obj.value = xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
}

You can e-mail me with any questions.

MEMBER FEEDBACK TO THIS TIP

I wanted to point out that this kind of functionality has been around for years -- I've personally been using the XML parser together with agents, and ?ReadViewEntries to get back results on the fly since 2002. It's amusing that only now when someone gives it a fancy name (AJAX) that everyone suddenly jumps on the bandwagon and claims they only just thought up how to do this. Articles like this have been around on the Internet for a while, including SearchDomino.com if I remember rightly.

It might be interesting to do a survey of your users to see just how many users were already aware of technology like this before some bright spark came up with the idea of naming the technology!

—Giles H.

******************************************

Good tip. However, the code is almost verbatim from another site: http://jibbering.com/2002/4/httprequest.html.

—Julian M.

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

This tip was submitted to the SearchDomino.com tip exchange by member Sean Burgess. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.

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.


Submit a Tip




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



RELATED CONTENT
JavaScript
Trap JavaScript runtime errors in Domino Web apps
JavaScript workaround fixes Lotus Notes 8.x PostOpen event issue
Write HTML and JavaScript in Notes view rows and columns on the Web
JavaScript detects Web browser type and version in Notes/Domino 8.0.2
JavaScript creates a jump box on a Lotus Notes Web form
How to create dynamic JavaScript in Notes Domino without formulas
Trap an attachment path via the Domino file upload control field
Converting Lotus Notes views to XML documents using JavaScript
Prevent errors on iFramed pages with JavaScript
How to add keyboard functionality for Lotus Notes documents

Ajax for Lotus Notes Domino
Top 10 Lotus Notes Domino programming and development tips of 2007
Ajax for Lotus Notes Domino
Editing fields in a Lotus Notes view with Ajax
Ajax code equivalent of the @DBColumn formula for Lotus Notes
A bevy of Notes/Domino development tips
A smorgasbord of Notes/Domino development tips
Latest Ajax tools from Nexaweb target SOA, Web 2.0
Delete documents over the Web using Ajax and JavaScript
Ajax threats worry researchers
New chapter and verse on Ajax security

JavaScript for Lotus Notes Domino
Trap JavaScript runtime errors in Domino Web apps
JavaScript workaround fixes Lotus Notes 8.x PostOpen event issue
Write HTML and JavaScript in Notes view rows and columns on the Web
JavaScript detects Web browser type and version in Notes/Domino 8.0.2
JavaScript creates a jump box on a Lotus Notes Web form
Top 10 Lotus Notes/Domino coding and development tips of 2008
How to create dynamic JavaScript in Notes Domino without formulas
Trap an attachment path via the Domino file upload control field
Converting Lotus Notes views to XML documents using JavaScript
Mimic Lotus Notes Domino application functionality on the Web

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