上傳如果通過form提交並且需要處理返回值。(其實用ajax上傳方式剛好,看需要)
可以這么做:
<form id="importBookForm" action="uploadReadBook.action" encType="multipart/form-data" method="post" target="hidden_frame"> <input id="myFile" name="myFile" type="File" /></a> <input id="submit" class="btn" type="submit" value="導入資源"> </form> <iframe name='hidden_frame' id="hidden_frame" style='display: none'></iframe>
js:
$('#hidden_frame').load(function(){
var text=$(this).contents().find("body").text();
// 根據后台返回值處理結果
var j=$.parseJSON(text);
if(j.status!=0) {
alert(j.msg);
} else {
alert('導入成功');
//location.href='BookResourceList.jsp'
}
});
