ajaxfileupload.js
- jQuery.extend({
- createUploadIframe: function(id, uri)
- {
- //create frame
- var frameId = 'jUploadFrame' + id;
- if(window.ActiveXObject) {
- var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
- if(typeof uri== 'boolean'){
- io.src = 'javascript:false';
- }
- else if(typeof uri== 'string'){
- io.src = uri;
- }
- }
- else {
- var io = document.createElement('iframe');
- io.id = frameId;
- io.name = frameId;
- }
- io.style.position = 'absolute';
- io.style.top = '-1000px';
- io.style.left = '-1000px';
- document.body.appendChild(io);
- return io
- },
- createUploadForm: function(id, fileElementId)
- {
- //create form
- var formId = 'jUploadForm' + id;
- var fileId = 'jUploadFile' + id;
- var form = $('<form action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
- var oldElement = $('#' + fileElementId);
- var newElement = $(oldElement).clone();
- $(oldElement).attr('id', fileId);
- $(oldElement).before(newElement);
- $(oldElement).appendTo(form);
- //set attributes
- $(form).css('position', 'absolute');
- $(form).css('top', '-1200px');
- $(form).css('left', '-1200px');
- $(form).appendTo('body');
- return form;
- },
- ajaxFileUpload: function(s) {
- // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
- s = jQuery.extend({}, jQuery.ajaxSettings, s);
- var id = s.fileElementId;
- var form = jQuery.createUploadForm(id, s.fileElementId);
- var io = jQuery.createUploadIframe(id, s.secureuri);
- var frameId = 'jUploadFrame' + id;
- var formId = 'jUploadForm' + id;
- // Watch for a new set of requests
- if ( s.global && ! jQuery.active++ )
- {
- jQuery.event.trigger( "ajaxStart" );
- }
- var requestDone = false;
- // Create the request object
- var xml = {}
- if ( s.global )
- jQuery.event.trigger("ajaxSend", [xml, s]);
- // Wait for a response to come back
- var uploadCallback = function(isTimeout)
- {
- var io = document.getElementById(frameId);
- try
- {
- if(io.contentWindow)
- {
- xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
- xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
- }else if(io.contentDocument)
- {
- xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
- xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
- }
- }catch(e)
- {
- jQuery.handleError(s, xml, null, e);
- }
- if ( xml || isTimeout == "timeout")
- {
- requestDone = true;
- var status;
- try {
- status = isTimeout != "timeout" ? "success" : "error";
- // Make sure that the request was successful or notmodified
- if ( status != "error" )
- {
- // process the data (runs the xml through httpData regardless of callback)
- var data = jQuery.uploadHttpData( xml, s.dataType );
- // If a local callback was specified, fire it and pass it the data
- if ( s.success )
- s.success( data, status );
- // Fire the global callback
- if( s.global )
- jQuery.event.trigger( "ajaxSuccess", [xml, s] );
- } else
- jQuery.handleError(s, xml, status);
- } catch(e)
- {
- status = "error";
- jQuery.handleError(s, xml, status, e);
- }
- // The request was completed
- if( s.global )
- jQuery.event.trigger( "ajaxComplete", [xml, s] );
- // Handle the global AJAX counter
- if ( s.global && ! --jQuery.active )
- jQuery.event.trigger( "ajaxStop" );
- // Process result
- if ( s.complete )
- s.complete(xml, status);
- jQuery(io).unbind()
- setTimeout(function()
- { try
- {
- $(io).remove();
- $(form).remove();
- } catch(e)
- {
- jQuery.handleError(s, xml, null, e);
- }
- }, )
- xml = null
- }
- }
- // Timeout checker
- )
- {
- setTimeout(function(){
- // Check to see if the request is still happening
- if( !requestDone ) uploadCallback( "timeout" );
- }, s.timeout);
- }
- try
- {
- // var io = $('#' + frameId);
- var form = $('#' + formId);
- $(form).attr('action', s.url);
- $(form).attr('method', 'POST');
- $(form).attr('target', frameId);
- if(form.encoding)
- {
- form.encoding = 'multipart/form-data';
- }
- else
- {
- form.enctype = 'multipart/form-data';
- }
- $(form).submit();
- } catch(e)
- {
- jQuery.handleError(s, xml, null, e);
- }
- if(window.attachEvent){
- document.getElementById(frameId).attachEvent('onload', uploadCallback);
- }
- else{
- document.getElementById(frameId).addEventListener('load', uploadCallback, false);
- }
- return {abort: function () {}};
- },
- uploadHttpData: function( r, type ) {
- var data = !type;
- data = type == "xml" || data ? r.responseXML : r.responseText;
- // If the type is "script", eval it in global context
- if ( type == "script" )
- jQuery.globalEval( data );
- // Get the JavaScript object, if JSON is used.
- if ( type == "json" )
- eval( "data = " + data );
- // evaluate scripts within html
- if ( type == "html" )
- jQuery("<div>").html(data).evalScripts();
- //alert($('param', data).each(function(){alert($(this).attr('value'));}));
- return data;
- }
- })
ajaxfileupload.js的更多相关文章
- 使用ajaxfileupload.js实现文件上传
ajaxFileUpload是一个异步上传文件的jQuery插件 语法:$.ajaxFileUpload([options]) options参数说明: 1.url 上传处理程序地址. 2,file ...
- ajaxfileupload.js的简单使用
上传文件 未选择任何文件 引入 <script src="../javaScript/ajaxfileupload.js"></script> <bu ...
- 利用ajaxfileupload.js异步上传文件
1.引入ajaxfileupload.js 2.html代码 <input type="file" id="enclosure" name="e ...
- jquery.ajaxfileupload.js
jquery.ajaxfileupload.js上传插件,利用iframe提交不刷新页面功能完成. /* // jQuery Ajax File Uploader // // @author: Jor ...
- java jfinal + ajaxfileupload.js 上传
功能上传 需求:同时上传多张图片 前端:jquery.ajaxfileupload.js 后端:jfinal upload.htm <html> <body> <div ...
- 文件上传ajaxfileupload.js插件
Html: <div class="container"> <form id="form" runat="serv ...
- SpringMVC结合ajaxfileupload.js实现文件无刷新上传
直接看代码吧,注释都在里面 首先是web.xml <?xml version="1.0" encoding="UTF-8"?> <web-ap ...
- 通过修改ajaxFileUpload.js实现多图片动态上传并实现预览
参考:http://smotive.iteye.com/blog/1903606 大部分我也是根据他的方法修改的,我也要根据name实现动态的多文件上传功能,但是有个问题使我一直无法实现多文件上传. ...
- 关于ajaxfileupload.js一些问题和上传图片就立即显示图片功能
ajaxfileupload.js是上传文件的一个插件,最近碰到的一个问题是在谷歌浏览器上传文件之后,原文本框中的文件名称消失,网上搜了好长时间也没有十分满意的答案.无刷新上传文件我想到的只有ajax ...
- 引用(ajaxfileupload.js) ajaxfileupload.js报这错jQuery.handleError is not a function
jQuery.handleError is not a function 原因是,经测试handlerError只在jquery-1.4.2之前的版本中存在,jquery-1.6 和1.7中都没有这个 ...
随机推荐
- loadrunner资源过滤器
通过该功能可以实现排除某个资源,很实用 Download Filters功能 帮助在回放脚本的时候对某些特定的访问进行屏蔽,解决页面读取中跨服务器带来数据影响的问题. 过滤规则中有3中策略,即URL. ...
- background为圆角的表框,dp转Px,Px转dp
圆角边框<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="ht ...
- 读懂Android项目结构目录
我们看到下图:当我们创建了第一Android项目的时候有没有被吓到.怎么这么多目录,好头晕啊!没事, 那我们今天就了解一下这些目录是做什么的: src: src 目录是放置我们所有 Java 代码的地 ...
- Ajax实现点击省份显示相应城市
功能:不用级联效果,自己写ajax,从接口读取省份城市数据,实现点击省份显示相应城市.后端根据省份ID,给前端返回城市. 一.DOM结构(套用blade模板) <div class=" ...
- jQuery操作radiobutton
1.获取某个radio选中的值,有三种方法 $("input:radio:checked").val()(*我最喜欢) ; $("input[type='radio'] ...
- Java第一天:安装搭建Java开发环境
Java是面向对象的语言.它是通过虚拟机的运行机制来实现“跨平台”的. 这里不多说其他的,进入正题先,学习任何语言前的第一步都是要先搭建好开发环境,Java开发环境搭建如下: 1.到官网 http:/ ...
- Codeforces 567C Geometric Progression(思路)
题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak. 感觉很多种做法的样子,我想到这么一种: 枚举中间的aj,看它左边有多少个aj/k右边有多 ...
- UIImage两种初始化的区别
UIImage可以通过以下两种方式进行初始化: //第一种初始化方式:[注意使用这种初始化的时候如果是png格式的可以不给后缀名,根据屏幕的的分辨率去匹配图片] UIImage *image = [U ...
- Teamwork[HDU4494]
Teamwork Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submi ...
- js 四舍五入保留二位小数
1. 最笨的办法....... [我就怎么干的.........] function get() { var s = 22.127456 + ""; var str = s.sub ...