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