Domino中运用ajax判断帐号是否存在的简单例子

 举例为帐号申请单,在开单的时输入一个帐号,系统判断该帐号是否存在于系统中。

1.在表单的JS Header中写判断的javascript函数:

var request;
function checkloginname(){
request = new ActiveXObject("Msxml2.XMLHTTP")
if (!request){
  request=new ActiveXObject("Microsoft.XMLHTTP");}
  request.onreadystatechange=aftercheckloginname;

  //这里假设数据库路径为mis/accounts.nsf,且表单中输入帐号的域是account,将这个域的值传递到代理中
  url="/mis/accounts.nsf/checkRepeatId?openagent&Id="+document.forms[0].account.value;
  request.open("post",url,true);
  request.send(null);
}
function aftercheckloginname(){
if (request.readystate==4){
  if (request.status==200){
   if (request.responseText.indexOf("1")>-1){
    alert (" 对不起,该帐号已经被使用!");
    document.forms[0].account.value="";
    document.forms[0].account.focus();
   }
  }
}
}

2.新建一个checkRepeatId的代理:

Sub Initialize
Dim ss As New NotesSession
Dim doc,docx As NotesDocument
Dim view As NotesView
Dim db As NotesDatabase

Set doc=ss.DocumentContext
Set db=ss.CurrentDatabase
Set view=db.GetView("checkid")     '这个试图即为帐号的试图,试图第一列为帐号
macro=|@RightBack(Query_String_Decoded;"=")|    '这句是获取从URL传过来的参数

id=Evaluate(macro,doc)

Set docx=view.GetDocumentByKey(id(0),True)
Print "Content-type: text/xml"
If Not docx Is Nothing Then
  Print "1"
Else
  Print "0"
End If
End Sub

3.在表单中输入帐号的域,这里举例为account,在域的onchange或者onblur事件中调用javascript方法checkloginname()

posted @ 2010-10-01 08:03  hannover  阅读(784)  评论(0编辑  收藏  举报