|
本帖最后由 hechengjin 于 2016-4-5 19:50 编辑
1.xmlhttprequest
function downloadCmEnterpriseDirecotry(name, obj){
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService).getBranch(null);
let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsISupports);
let url = prefBranch.getCharPref("cm.enterprise.dir.request");
//let url = "http://testmail1/service/serviceapi.do?func=serviceapi:corpAddr&sid=lJ8g9RCqKRVRHRLxLrKSRRnUbMlsOhBL000001&r=816cb4fba8de414e9fcd72098e28e8bf";
request.open("POST", url, true);
request.overrideMimeType("application/xml");
request.setRequestHeader("Cache-Control", "no-cache");
request.addEventListener("error", function(event) {onError_downloadCmEnterprise(event, name, obj); } ,false);
request.addEventListener("load", function(event) {onLoad_downloadCmEnterprise(event, name, obj); }, false);
// 格式化函数
String.prototype.format= function(){
var args = arguments;
return this.replace(/\{(\d+)\}/g,function(s,i){
return args;
});
}
// 解密密码
let plainPwd = decodePassword(name, obj.password);
try{
var body = '{"email":"{0}","passwd":"{1}"}'.format(name, plainPwd);
} catch (e) {
mm3w.log("downloadCmEnterpriseDirecotry error = " + e);
}
request.send(body);
}
function onLoad_downloadCmEnterprise(event, name, obj){
let aRequest = event.target;
let json = null;
try {
let responseText = aRequest.responseText;
var json = eval('('+aRequest.responseText+')');
if (json.code != "S_OK"){
enableRefresh(obj.menuJson);
updateloadingEnd(name);
return;
}
} catch (e) {
mm3w.log("onLoad_downloadCmEnterprise = " + e);
return;
}
mm3w.log("request cm enterprise dir ok!");
// 保存企业通讯录到本地
saveEnterpriseDirectoryToLocal(json, name, obj);
}
2.jquery
|
|