B/S离线技术设计与实现

以下内容均转载自[url="http://hi.baidu.com/crestcloud/blog/item/32ce342d24322130349bf7d0.html"]这儿[/url],仅供参考,代码本人并未验证使用,先预存于此。
==========================我是分割线======================================

其实B/S的离线很好办,数据在缓存中就可以实现,但如果有数据回调或是数据验证,就不问题了.
所以实现我个人认为有这相几个方法:
方法一:
1)数据缓以数组或XML缓存在客户端的网页中,用JS进行交互;
2)保存时,如果联机就直接保存到服务器,如果断线就保存在网页的XML或JS数组;
3)网络接通时,用XMLHTTP方式将离线数据上传到服务器
方法二:
1)数据缓存到客户端的XML文件,也JS的方式加载到页面;
2)保存时,文件先保存在客户端XML文件,如果网络联机就直接送到服务器,并清空XML;
3)网络接通进,将XML同步到服务器
两种方式都可以实现离线和断电功能;也各有优点,
方法一就是用户不能关闭当前的网站或系统,因为XML可用是以Frame的方隐藏的网页上的,关闭后,数据一样丢失..
方法二需要解决在客户端读写文件的权限与加解密问题;
我个人选择的是方法二,用ActievX + 数字签名 + XML + MD5文件验证实现

<script type="text/javascript" >
function SearchData()
{
var InputParam;
InputParam = document.getElementById('<%= this.UltraWebTab1.FindControl("WebTextEdit1").UniqueID %>').value;

for(var i=0;i<cst10100[0].length;i++)
{
if(cst10100[0][i]==InputParam)
{
igedit_getById('<%= this.UltraWebTab1.FindControl("WebTextEdit2").UniqueID %>').setValue(cst10100[4][i]);
igedit_getById('<%= this.UltraWebTab1.FindControl("WebTextEdit3").UniqueID %>').setValue(cst10100[7][i]);
igedit_getById('<%= this.UltraWebTab1.FindControl("WebTextEdit4").UniqueID %>').setValue(cst10100[5][i]);
igedit_getById('<%= this.UltraWebTab1.FindControl("WebTextEdit5").UniqueID %>').setValue(cst10100[6][i]);
igedit_getById('<%= this.UltraWebTab1.FindControl("WebTextEdit8").UniqueID %>').setValue(cst10100[2][i]);
}
}
var ListBoxControl=document.getElementById('<%= this.UltraWebTab1.FindControl("ListBox1").UniqueID %>');
for(var z=ListBoxControl.options.length;z>0;z--)
{
ListBoxControl.options[z-1].parentNode.removeChild(ListBoxControl.options[z-1]);
}
for(var z=0;z<cst10101[0].length;z++)
{
if (cst10101[0][z]==InputParam)
{
var newOption=document.createElement("OPTION");
newOption.text=cst10101[3][z];
newOption.value=cst10101[3][z];
ListBoxControl.options.add(newOption);
}
}

var dropdownlistControl=document.getElementById('<%= this.UltraWebTab1.FindControl("DropDownList2").UniqueID %>');
for(var z=dropdownlistControl.options.length;z>0;z--)
{
dropdownlistControl.options[z-1].parentNode.removeChild(dropdownlistControl.options[z-1]);
}
for(var z=0;z<cst10101[0].length;z++)
{
if (cst10101[0][z]==InputParam)
{
var newOption=document.createElement("OPTION");
newOption.text=cst10101[1][z];
newOption.value=cst10101[1][z];
dropdownlistControl.options.add(newOption);
}
}

}

//设置时间
var igdrp =igdrp_getComboById('<%= this.UltraWebTab1.FindControl("WebDateChooser1").UniqueID %>');
igdrp.setText('2007-4-11');

//添加节点
for(var z=0;z<cst10104[0].length;z++)
{
var resultId=document.getElementById('<%= this.UltraWebTab1.FindControl("DropDownList1").UniqueID %>');
var newOption=document.createElement("OPTION");
newOption.text=cst10104[1][z];
newOption.value=cst10104[0][z];
resultId.options.add(newOption);
}
</script>

<IE:CLIENTCAPS ID="oClientCaps" style=behavior:url(#default#clientCaps)/>
<script type="text/javascript" >

function getstatus()
{
if(oClientCaps.connectionType=="lan")
return "online";
else
return "offline";
}

function runClock()
{
theTime = window.setTimeout("runClock()", 1000);
status=getstatus();
//if (getstatus() =="online")
//判断本地是否有离线数据,当存在时进行同步
//SyncXML()
}
runClock()

function InsertData()
{
var CommonArry= new Array();
CommonArry[0]= new Array();
CommonArry[0][0]= 'cust';
CommonArry[0][1]= document.getElementById('<%= this.UltraWebTab1.FindControl("WebTextEdit1").UniqueID %>').value; // value
CommonArry[0][2]= "2";

CommonArry[1]= new Array();
CommonArry[1][0]= 'description';
CommonArry[1][1]= document.getElementById('<%= this.UltraWebTab1.FindControl("WebTextEdit8").UniqueID %>').value; // value
CommonArry[1][2]= "2";

CommonArry[2]= new Array();
CommonArry[2][0]= 'DeliveryAddr';
CommonArry[2][1]= document.getElementById('<%= this.UltraWebTab1.FindControl("WebTextEdit2").UniqueID %>').value; // value
CommonArry[2][2]= "2";

CommonArry[3]= new Array();
CommonArry[3][0]= 'PhoneNo';
CommonArry[3][1]= document.getElementById('<%= this.UltraWebTab1.FindControl("WebTextEdit4").UniqueID %>').value; // value
CommonArry[3][2]= "2";

CommonArry[4]= new Array();
CommonArry[4][0]= 'FaxNo';
CommonArry[4][1]= document.getElementById('<%= this.UltraWebTab1.FindControl("WebTextEdit5").UniqueID %>').value; // value
CommonArry[4][2]= "2";

insertData('custinfo',CommonArry);

document.getElementById("KunleneXML").WriteXML("JohnnyOfflineLineXML",doc.xml);


}


</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值