Sunday, June 04, 2006

POST data to Domino agent using AJAX

Many people on Domino forums ask about getting data from LotusScript agent without refreshing the page, as if it was a pure javascript function call. It is possible with AJAX, here is an example and a live demo.

This example sends text located in a DIV tag on a web page to a LotusScript agent and updates the DIV element with response data received back from the agent.


Live example


Sub Initialize

< script >
var http_request = false;
function makePOSTRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}

http_request.onreadystatechange = GetResponse;
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
}

function GetResponse() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
result = http_request.responseText;
document.getElementById('test').innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}
}

function GetAgentData(txtdata) {
var poststr = txtdata; //encodeURI(txtdata);
makePOSTRequest('/test.nsf/postagent?openagent', poststr);
}
< /script >



-------------- LOTUSSCRIPT AGENT ---------------------
Sub Initialize
Dim session As New NotesSession
Dim doc As NotesDocument
Set doc=session.DocumentContext
req=doc.Request_Content(0)
For x=Len(req) To 1 Step -1
tmp=tmp+Mid(req,x,1)
Next
Print tmp
End Sub

8 comments:

dhd said...

welcome to the wow power leveling cheap wow power leveling service site, buy cheap wow gold,wotlk gold,world of warcraft power leveling buy wow gold

world of warcraft gold said...

Weaknesses of World Of Warcraft Gold the client-server model used by World of Warcraft have been wow power levelingexploited in order to crash the cluster of servers that make up a realm. Exploits also include characters being able to instantly change location or teleport. The situation Cheap Wow Goldbecame worse when trying to coordinate activities across a number of players cheapest wow goldor guilds on the same realm.World of Warcraft Lead trade4gameProducer, stated that new realms would be introduced to relieve the burden on existing ones. Existing realms would be upgraded.

Although the game wow gold follows a similar model to others in the genreand was noted for having wow gold cheapmany familiar concepts from roleplaying games, the new approaches oggsaleto reduce pauses between game encounters was well liked. At various times, World of Warcraft players live4gamehave experienced problems with connecting to and logging in to wow gold for sale the game. Sudden server crashes that would force realms offline also occurred.

Best World of Warcraft Gold Guide said...

great post man :)

Matt Moriarty said...

Great post. Has made the world of Ajax accessible to me using Lotus Notes.

dreaz said...

I am grateful to you for this great content.aöf thanks radyo dinle cool hikaye very nice sskonlycinsellik very nice ehliyet turhoq home free kadın last go korku jomax med olsaoy hikaye lesto go müzik dinle free only film izle love aşk 09sas mp3 indir

Adi said...
This comment has been removed by the author.
Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa page and other update like as Beratnya Mengembalikan Jati Diri Bangsa, Mengembalikan Jati Diri Bangsa di perpanjang and Jangan Berhenti Mengembalikan Jati Diri Bangsa. Thank you So much.

Oes Tsetnoc | Lanjutkan Mengembalikan Jati Diri Bangsa

liuhua said...

After read your blog, I think you are a wonderful person, for your blog is the best one I have ever seen. If you do not mind, I would like to know do you like fashion? Have you ever heard of polo shirts, which are very chic, especially the polo t shirts, I love them very much. I also like playing tennis rackets, it can keep healthy, what do you like to do? I consider it as my great pleasure to introduce myself as the outlet of polo t shirts women
polo t shirts on sale
and the warmly welcomed
polo t shirts for women
Now. I'd like to introduce our masterpieces, such as
polo shirts on sale
polo shirts men
men's polo shirt
men polo shirt
mens polo shirts
mens polo shirt
besides we also sell
cheap polo shirts
discount polo shirts
men's polo shirts
women's polo shirts
Which are popular with fashinable people. We are also the outlet of
cheap tennis racket
discount tennis racket
in this sporty season, we recommend
prince tennis racquet
head tennis rackets
wilson tennis racket
babolat tennis racquet
There more new products in our store online, we are expecting you to come. We can say that you must find your satisfied things in our store.