iframe 实现的文件异步上传解析
iframe 实现的文件异步上传解析,首先我们来看主页面main.htm,上传文件的FORM的代码:
以下为引用内容:
<form id="uploadform" method="post" action="upload.do" enctype="multipart/form-data" target="result_frame" >
<input type="file" id="uploadFile" name="uploadFile" />
</form>
注意上面的 target="result_frame" 这个form的属性,指示了form提交后响应的对象
这个就是响应的iframe:
以下为引用内容:
<iframe id="result_frame" name="result_frame"></iframe>
在主页面中有这样一个脚本,脚本的作用是供iframe子页调用
以下为引用内容:
<script type="text/javascript">
function callback(msg) {
alert(msg);
}
</script>
服务器端代码:
在这里我不针对某种语言,不过以php asp 和 c# 为例
php :
以下为引用内容:
echo "<script type='text/javascript'>parent.callback('ok')</script>";
c# :
以下为引用内容:
Response.Write("<script type='text/javascript'>parent.callback('ok')</script>");
asp :
以下为引用内容:
Response.Write("<script type='text/javascript'>parent.callback('ok')</script>")