iframe仿Ajax上传文件
2015-10-17 21:00
197 查看
利用iframe框架完成文件上传
前端页面
01.php
页面效果
前端页面
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>iframe伪装上传文件</title> <script type="text/javascript" src="./jquery-2.0.0.min.js"></script> <script type="text/javascript"> function up(){ var fname='up'+Math.random();//产生随机name值 $('<iframe name="'+fname+'" width="0" height="0" frameBorder="0"></iframe>').appendTo($('body'));//创建iframe标签, $('form:first').attr('target',fname);//将php返回信息引到这个框架中来,不发生页面跳转 $('#xinxi').html('正在上传');//上传过程中的显示 //return false; } </script> </head> <body> <h1>iframe模拟Ajax文件上传</h1> <h2 id="xinxi"></h2> <form action="01.php" method="post" onsubmit="return up();" enctype="multipart/form-data"> <p><input type="file" name="pic" /></p> <p><input type="submit" value="上传"/></p> </form> </body> </html>
01.php
<?php if(empty($_FILES)){ echo 'no file'; } sleep(2); $error=$_FILES['pic']['error']==0?'succ':'fail'; echo "<script>parent.document.getElementById('xinxi').innerHTML='$error'</script>"; ?>
页面效果
相关文章推荐
- VTK实现Delaunay三角化
- 逻辑运算符
- 基于HttpClient的java后台访问URL
- Webservice原理解析
- docker和nodejs
- MySql-解决中文乱码问题
- 排版设计之统一元素间隔
- devexpress皮肤设置
- Chapter 3 Growth of functions
- 测试发帖
- SignalR实时推送
- 作业五——团队项目——需求规格说明书
- 【BZOJ】【P4281】【ONTAK2015】【Związek Harcerstwa Bajtockiego】【题解】【倍增】
- 关系运算符
- Java相对路径总结
- Spark控制ReduceTask数量
- Xcode快捷键
- 【UWP应用开发实战】第一弹 使用剪切板
- json对象转java对象
- 操作系统之PCB的组成及作用