日期:2014-05-18  浏览次数:20460 次

在AJAX中如何避免重复添加记录
为了避免页面刷新闪烁的问题,我用了AJAX(我是初学者~_~),其中有个按钮是用来添加记录的,但是有时候网速太慢了,点击后半天都没有反映,用户可能重新点击该按钮,所以会出现重复添加记录的情况,不知道各位高手是如何解决该问题的,请指点下方法

------解决方案--------------------
按钮添加JS脚本事件,点击后出现正在处理的层,处理完后恢复

JScript code

 <script language="javascript" type="text/javascript">
      function Check()  
        {
            //弹出提示
            if(!confirm("确定要进行吗?"))
            {    
                return false;
            }
            else
            {
                ShowMessageBusing();
                return true;
            }
        } 
        
        function ShowMessageBusing()
        {
            for(ipos = 0; ipos <  document.body.childNodes.length;ipos++) 
            { document.body.childNodes[ipos].style.display = 'none';}
            var div = document.createElement('div');
                div.innerHTML = "<TABLE  style='FILTER: Alpha(Opacity=75);WIDTH: 360px; HEIGHT: 40px' borderColor='#33ccff' height='40' cellSpacing='0' cellPadding='0' width='360' align='center' border='1'><TR><TD vAlign='middle' align='center' bgColor='buttonhighlight' colSpan='' rowSpan=''><FONT color='#0099ff' size='2'><STRONG>正在处理中,请稍候...</STRONG></FONT></TD></TR></TABLE>";
                div.style.position = 'absolute';
                div.style.left = '300px';
                div.style.top = '250px';
                div.style.zIndex = '999';
                div.style.height = '40px';
                div.style.width = '360px';
                div.style.borderColor = '#33ccff';
                div.style.borderWidth = '1px';
                div.style.borderStyle = 'solid';
                div.style.textAlign = 'center';
                div.style.fontFamily = '宋体';
                div.style.fontWeight = 'bold';
                div.style.fontSize = '12px';
                div.style.backgroundColor = '#6699ff';
                document.body.appendChild(div);
                //div.style.left = (document.body.clientWidth-div.style.width.substring(0,div.style.width.length-2))/2;
                //div.style.top =  document.body.scrollTop+(document.body.clientHeight- div.style.height.substring(0,div.style.height.length-2)  )/2;
        }
    </script>