模態對話框,沒有opener,不能用window.opener.location.reload();或window.parent.location.reload();
要經過返回值來判斷關閉後刷新。java
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框架,只能經過跳轉頁面來給提示,因爲在模態對話框中,若是再提交頁面的話,用戶體驗就太很差了,所以要選擇異步提交,那怎樣異步上傳文件呢? ajax
從網上找到了一個異步上傳文件的插件:ajaxfileupload.jsjson
$.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>