首页 > 代码库 > Ajax获取代理返回的Json数据
Ajax获取代理返回的Json数据
【背景】
Ajax在开发过程中使用的很多,局部刷新、动态加载等功能,非常受到用户的青睐,它可以接收代码返回的xml、html、Json等格式,本人主要讲述返回Json格式。
下面的代码是判断用户输入的密码是否与当前密码一致。
【参考代码】
1.Js代码:function CreateXMLHTTP() { // 创建AJAX请求对象,系统不考虑跨浏览器情况 var progids = ["Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP.2.6","MSXML2.XMLHTTP","Microsoft.XMLHTTP"]; var o; for(var i = 0; i < progids.length; i++){ try{ o = new ActiveXObject(progids[i]); return o; } catch (e) {}; } return null; }
// 检查现在的密码是否填写正确 function fnCheckOldPasswd(){ var objHTTP= CreateXMLHTTP(); var d = new Date(); var vurl = "/"+document.getElementById("thisDb").value+"/ajaxCheckOldPasswd?OpenAgent&OldPass="+escape(document.getElementById("OldPassword").value)+"&curUser="+escape(document.getElementById("CurUser").value) + "&d=" + d.getTime(); objHTTP.open("GET", vurl, false, "", ""); objHTTP.setRequestHeader("If-Modified-Since","0"); objHTTP.send(false); var getOptions = objHTTP.responseText; getOptions = getOptions.replace(/\n/ig,""); var oJson = eval("(" + getOptions + ")"); if(oJson && oJson.oReturn=="true"){ return true; }else{ return false; } }
说明:
1)通过objHTTP.responseText获取代理返回Json字符串信息;
2)通过eval("(" + getOptions + ")")将Json字符串转换成Json对象
2.Lotuscript代码:
Option Public Option Declare Sub Initialize On Error Goto ErrorHandle Dim ss As New NotesSession Dim namesDb As NotesDatabase Dim namesView As NotesView Dim namesDoc As NotesDocument Dim curDoc As NotesDocument Set curDoc = ss.Documentcontext Dim sCurUser As String Dim sOldPass As String Dim sReturn As String sReturn = "false" Dim QueryList As Variant Dim String_Query As String Dim i As Integer String_Query = curDoc.query_string_decoded(0) Msgbox "String_Query==" & String_Query 'Msgbox String_Query QueryList = fnUnSerialize(String_Query) sCurUser = QueryList("curUser") sOldPass=QueryList("OldPass") MsgBox "sCurUser=" & sCurUser & ",sOldPass=" & sOldPass Dim v As Variant Dim passwd As String v = Evaluate(|@Password("| & sOldPass & |")|) passwd = v(0) MsgBox "passwd=" & passwd Set namesDb = ss.Getdatabase("xx", "names.nsf") Set namesView = namesDb.Getview("PeopleByCNName") Set namesDoc = namesView.Getdocumentbykey(sCurUser, true) If Not namesDoc Is Nothing Then MsgBox namesDoc.HTTPPassword(0) If namesDoc.HTTPPassword(0)=passwd Then sReturn = "true" End If End If Print |Content-Type: text/plain; charset="GB2312"| exitSub: Print |{"oReturn":"| & sReturn & |"}| MsgBox |{"oReturn":"| & sReturn & |"}| Exit Sub ErrorHandle: msgErr "Initialize" GoTo exitSub End Sub Function fnUnSerialize(strQuery As String) As Variant On Error GoTo err_handle Dim QueryList List As String Dim tmp1 As Variant Dim tmp2 As Variant tmp1 = Split(strQuery,"&") ForAll t In tmp1 tmp2 = Split(t,"=") If UBound(tmp2)=1 And tmp2(0) <> "" Then QueryList(tmp2(0)) = tmp2(1) End If End ForAll fnUnSerialize = QueryList Exit Function err_handle: MsgBox "fnParam "+Str(Erl) End Function
Ajax获取代理返回的Json数据
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。