通过在VIOS上 复制lV的方式快速起虚机
2013-02-05 11:23
274 查看
原站连接
现在的ajax上传,都是用iframe做过渡的。实现的方式是:
1.js 生成或者页面中插入隐藏的iframe元素。
<iframe id='upiframe' name='upiframe' onload='getHtml()'></iframe>
2.提交的表单放到生成的iframe页面里面,
提交目标 target = 'upiframe' ,
3.监听iframe的onload事件,获取docuemnt ,及上传后返回的信息。
下面是代码,看起来不是很多,用起来也很方便
html中的设置
PHP and AJAX Image Upload
现在的ajax上传,都是用iframe做过渡的。实现的方式是:
1.js 生成或者页面中插入隐藏的iframe元素。
<iframe id='upiframe' name='upiframe' onload='getHtml()'></iframe>
2.提交的表单放到生成的iframe页面里面,
提交目标 target = 'upiframe' ,
3.监听iframe的onload事件,获取docuemnt ,及上传后返回的信息。
下面是代码,看起来不是很多,用起来也很方便
function $m(theVar){ return document.getElementById(theVar) } function remove(theVar){ var theParent = theVar.parentNode; theParent.removeChild(theVar); } function addEvent(obj, evType, fn){ if(obj.addEventListener) obj.addEventListener(evType, fn, true) if(obj.attachEvent) obj.attachEvent("on"+evType, fn) } function removeEvent(obj, type, fn){ if(obj.detachEvent){ obj.detachEvent('on'+type, fn); }else{ obj.removeEventListener(type, fn, false); } } function isWebKit(){ return RegExp(" AppleWebKit/").test(navigator.userAgent); } function ajaxUpload(form,url_action,id_element,html_show_loading,html_error_http){ var detectWebKit = isWebKit(); form = typeof(form)=="string"?$m(form):form; var erro=""; if(form==null || typeof(form)=="undefined"){ erro += "The form of 1st parameter does not exists.\n"; }else if(form.nodeName.toLowerCase()!="form"){ erro += "The form of 1st parameter its not a form.\n"; } if($m(id_element)==null){ erro += "The element of 3rd parameter does not exists.\n"; } if(erro.length>0){ alert("Error in call ajaxUpload:\n" + erro); return; } var iframe = document.createElement("iframe"); iframe.setAttribute("id","ajax-temp"); iframe.setAttribute("name","ajax-temp"); iframe.setAttribute("width","0"); iframe.setAttribute("height","0"); iframe.setAttribute("border","0"); iframe.setAttribute("style","width: 0; height: 0; border: none;"); form.parentNode.appendChild(iframe); window.frames['ajax-temp'].name="ajax-temp"; var doUpload = function(){ removeEvent($m('ajax-temp'),"load", doUpload); var cross = "javascript: "; cross += "window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0);"; $m(id_element).innerHTML = html_error_http; $m('ajax-temp').src = cross; if(detectWebKit){ remove($m('ajax-temp')); }else{ setTimeout(function(){ remove($m('ajax-temp'))}, 250); } } addEvent($m('ajax-temp'),"load", doUpload); form.setAttribute("target","ajax-temp"); form.setAttribute("action",url_action); form.setAttribute("method","post"); form.setAttribute("enctype","multipart/form-data"); form.setAttribute("encoding","multipart/form-data"); if(html_show_loading.length > 0){ $m(id_element).innerHTML = html_show_loading; } form.submit(); }
html中的设置
<!-- VERY IMPORTANT! Update the form elements below ajaxUpload fields: 1. form - the form to submit or the ID of a form (ex. this.form or standard_use) 2. url_action - url to submit the form. like 'action' parameter of forms. 3. id_element - element that will receive return of upload. 4. html_show_loading - Text (or image) that will be show while loading 5. html_error_http - Text (or image) that will be show if HTTP error. VARIABLE PASSED BY THE FORM: maximum allowed file size in bytes: maxSize = 9999999999 maximum image width in pixels: maxW = 200 maximum image height in pixels: maxH = 300 the full path to the image upload folder: fullPath = http://www.atwebresults.com/php_ajax_image_upload/uploads/ the relative path from scripts/ajaxupload.php -> uploads/ folder relPath = ../uploads/ The next 3 are for cunstom matte color of transparent images (gif,png), use RGB value colorR = 255 colorG = 255 colorB = 255 The form name of the file upload script filename = filename --> <form action="scripts/ajaxupload.php" method="post" name="standard_use" id="standard_use" enctype="multipart/form-data"> <p><input type="file" name="filename" /></p> <button onclick="ajaxUpload(this.form,'scripts/ajaxupload.php?filename=filename&maxSize=9999999999&maxW=200&fullPath=http://www.atwebresults.com/php_ajax_image_upload/uploads/&relPath=../uploads/&colorR=255&colorG=255&colorB=255&maxH=300','upload_area','File Uploading Please Wait...<br /><img src=\'images/loader_light_blue.gif\' width=\'128\' height=\'15\' border=\'0\' />','<img src=\'images/error.gif\' width=\'16\' height=\'16\' border=\'0\' /> Error in Upload, check settings and path info in source code.'); return false;">Upload Image</button> </form>
相关文章推荐
- 快速实现兼容的js复制方式。有点非正规,通过非正规的排版实现。
- python通过shutil实现快速文件复制的方法
- 通过BlukLoad的方式快速导入海量数据
- 通过BlukLoad的方式快速导入海量数据
- C# 快速高效率复制对象另一种方式 表达式树
- 977dh用vbs通过wsh创建桌面快捷方式,快速启动,修改ie主页的恶意代码 ...
- 通过mmap函数快速实现文件复制
- cmd里面快速粘贴复制的设置方式以及初始位置设置
- 通过复制oracle软件方式安装oracle数据库
- php通过文件流方式复制文件的方法
- JAVA复制文件最快速的方法:用文件通道的方式来进行文件复制
- [原]在Linux中通过本地复制的方式创建多一个Oracle数据库
- 如何通过 DNS 验证方式获取Let’s Encrypt 证书的快速脚本
- 通过BlukLoad的方式快速导入海量数据
- 域环境下的通过DFS复制实现文件的网络冗余【网络存储新方式】
- Hbase通过BulkLoad的方式快速导入海量数据
- 通过复制-粘贴的方式将文件从本地上传到服务器上
- mysql通过gitd方式实现多线程主从复制
- C# 快速高效率复制对象的几种方式
- hbase通过BulkLoad的方式快速导入海量数据