html form表单提交后处理返回数据

上传如果通过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'
    }
});
原文地址:https://www.cnblogs.com/peng14/p/5025692.html