善待自己,珍惜今天,恩泽他人,享受生活

不放弃任何解决困难的机会,人的一生就是解决困难的过程。 当我们走完一生才能说没有问题要解决了。 面对工作、生活上的压力,面对来自家庭、朋友、同事、上司等的困惑。 要排除万难,否则我们就会被万难排除!

博客园 首页 新随笔 联系 订阅 管理

模态对话框,没有opener,不能用window.opener.location.reload();或window.parent.location.reload();
要通过返回值来判断关闭后刷新

function   openWindow(url,   xsize,   ysize)
{
  res   =   showModalDialog(url, " ", "dialogWidth: "+xsize+ ";dialogHeight: "+ysize+ ";status=no;help:no;center:yes ")  
    if   (res== 'ok ')   window.location.reload(1)
}

and   in   the   dialog   use
<td   onclick= "window.returnValue= 'ok ';window.close();   "> Close </td> 

上传文件由于要给一个上传是否成功的提示,因为我们用的是struts2框架,只能通过跳转页面来给提示,由于在模态对话框中,如果再提交页面的话,用户体验就太不好了,因此要选择异步提交,那怎样异步上传文件呢?

从网上找到了一个异步上传文件的插件:ajaxfileupload.js

 $.ajaxFileUpload(
                   {
		                url:'${pageContext.request.contextPath}/${param.url}.action',            //需要链接到服务器地址
		                secureuri:false,
		                fileElementId:'upLoadFile',                        //文件选择框的id属性
		                dataType: 'json',                                     //服务器返回的格式,可以是json
		                success: function (data, status)            //相当于java中try语句块的用法
		                {      
			                if(data.success==true)
			                {
			                    alert('上传成功!');
			                    window.returnValue='ok';//返回值
				  	    window.close(); //关闭窗口
				         }
				  	else if(data.success ==false){		
						  alert('上传失败!');
			                }
		                },
		                error: function(){
					//alert("error");
			         },
			         complete:function(XMLHttpRequest, textStatus){
			               //alert("complete");
			        }
                     }

5. form

<form action="${pageContext.request.contextPath}/uploadFile.action"					
method="post" enctype="multipart/form-data" target="_self">
<input type="file"  name="upLoadFile" id="upLoadFile"  />
<input type="button" value="上传" onclick="ajaxFileUpload()" />
</form>
posted on 2013-08-23 17:32  笨笨丁  阅读(464)  评论(0编辑  收藏  举报