要想让表单无刷新提交,需要用到表单的target属性,然后页面放置一个iframe,target属性指向iframe即可实现
测试程序如下:
<script>
function upload(fileObj)
{
if(fileObj.value)
{
document.uploadForm.action = "ajax_upload.action";
document.uploadForm.submit();
}
return false;
}
</script>
<%--无刷新上传图片--%>
<form target="check_file_frame" enctype="multipart/form-data" method="POST" name="uploadForm">
<input type="file" style="width: 250px;" οnchange="upload(this);" name="uploadFile" id="uploadFile"></br>
<iframe style="display: none;" id="check_file_frame" name="check_file_frame"></iframe>
</form>
测试程序如下:
<script>
function upload(fileObj)
{
if(fileObj.value)
{
document.uploadForm.action = "ajax_upload.action";
document.uploadForm.submit();
}
return false;
}
</script>
<%--无刷新上传图片--%>
<form target="check_file_frame" enctype="multipart/form-data" method="POST" name="uploadForm">
<input type="file" style="width: 250px;" οnchange="upload(this);" name="uploadFile" id="uploadFile"></br>
<iframe style="display: none;" id="check_file_frame" name="check_file_frame"></iframe>
</form>