ajax是無法提交文件的,所以在上傳圖片并預覽的時候,我們經常使用Ifame的方法實現看似異步的效果。但是這樣總不是很方便的,AjaxFilleUpload.js對上面的方法進行了一個包裝,使得我們不用去管理Iframe的一系列操作,也不用影響我們的頁面結構,實現異步的文件提交。
html:
復制代碼 代碼如下:
<input type="file" hidden="hidden" accept=".zip" />
復制代碼 代碼如下:
$.ajaxFileUpload({
url:'${pageContext.request.contextPath}/Manage/BR_restorePic.action', //需要鏈接到服務器地址
secureuri:false,
fileElementId:'file_upload', //文件選擇框的id屬性
dataType: 'text', //服務器返回的格式,可以是json、xml
success: function (data, status) //相當于java中try語句塊的用法
{
$('#restoreDialog').html(data);
//alert(data);
},
error: function (data, status, e){ //相當于java中catch語句塊的用法
$('#restoreDialog').html("上傳失敗,請重試");
}
});
復制代碼 代碼如下:
$('#file_upload').replaceWith('<input type="file" hidden="hidden" accept=".zip" />');
新聞熱點
疑難解答
圖片精選