欢迎光临
我们一直在努力

ASP 如何避免数据重复提交

ASP提交数据的时候做数据合法校验,校验通过后打开一个“隐藏”的窗口(其实是显示在屏幕之外的一个小窗口)来进行提交处理,数据保存成功后刷新父窗口并用alert显示保存状态然后关闭此隐含窗口,这样用户就无法用back返回而且提交后的窗口已关闭,避免重复刷新。极数博客:陈佳裕博客">陈佳裕博客  下面是演示,只有2个文件:submitdemo.ASP 和 save.ASP,非常简单,只要稍微修改就可以应用到你的程序里,希望对大家有帮助。    1.submitdemo.ASP 演示数据输入和校验主程序<HTML><head><title>new/edit</title><meta http-equiv="Content-Type" content="text/HTML; charset=gb2312"><script language="javascript"><!--//打开一个位置在屏幕之外的窗口function NewHideWindow(mypage,myname){    LeftPosition = parseInt(screen.width)+1;    TopPosition = parseInt(screen.height)+1;    settings ='height=100,width=100,top='+TopPosition+',left='+LeftPosition+',scrollbars=0,resizable=0,status=0'    window.open(mypage,myname,settings)}//数据校验函数function validate(theForm) {    if(theForm.text1.value == "")        {        alert("请填写text1的数据!");        theForm.text1.focus();        return (false);        }    if(theForm.text2.value == "")        {        alert("请填写text2的数据!");        theForm.text2.focus();        return (false);        }    return (true);}//调用上面两个函数校验输入的数据并打开保存数据窗口function savewin(theForm){   if(validate(theForm))   {      NewHideWindow('about:blank','SaveWindow');      return true;   }   return false;}--></script></head><body bgcolor="#FFFFFF"><!--注意这里的 onsubmit 的函数调用和 target 中的窗口名字要和 savewin 函数中NewHideWindow写的窗口名一致(注意大小写)--><form name="form1" action="save.ASP"  onsubmit="return savewin(this);" target="SaveWindow">  text1:   <input type="text" name="text1"><br>  text2:  <input type="text" name="text2">  <input type="submit" name="Submit" value="提 交"></form></body></HTML>2.save.ASP 保存数据处理<%Dim intStatus'**********************************************************'*  保存数据到数据库,在此最好再进行一次数据的合法校验    *'*  ...                                                   *'*  If 保存成功 Then                                      *'*     intStatus = 1                                      *'*  Else                                                  *'*     intStatus = -1                                     *'*  End If                                                *'**********************************************************'成功测试'intStatus = 1'失败测试intStatus = -1%><HTML><head><title> </title><meta http-equiv="Content-Type" content="text/HTML; charset=gb2312"><script><!--<%      If intStatus=1 Then         response.write "window.opener.location.reload();"         response.write "alert('保存成功!');"         response.write "window.close();"      Else         If intStatus=-1 Then            response.write "alert('保存失败,请检查输入的数据是否完整有效!');window.close();"         Else            response.write "window.close();"         End If      End If%>//--></script></head><body bgcolor="#FFFFFF"></body></HTML

赞(0)
未经允许不得转载:福利吧|福利社|fuliba » ASP 如何避免数据重复提交

相关推荐

  • 暂无文章