ajax文件上传兼容ie7,ajaxfileUpload.js兼容ie7、8、9、10、11、firefox、chrome等浏览器的js代码...

// JavaScript Document

jQuery.extend({

createUploadIframe:function(id,uri)

{

//create frame

varframeId='jUploadFrame'+id;

if(window.ActiveXObject)//var io = document.createElement('');

(jQuery.browser.version=="9.0"||jQuery"10.0"){

vario=document.createElement('iframe');

io.id=frameId;

io.name;

}else"6.0""7.0""8.0"'');

(typeofuri=='boolean'){

io.src'javascript:false';

}

'string'=uri}

else{

);

io;

io}

io.style.position'absolute'.top'-1000px'.left;

document.body.appendChild(io);

returnio},

createUploadFormfileElementIddata//create form

varformId'jUploadForm';

varfileId'jUploadFile'varform=jQuery'

'varoldElement'#'+fileElementId);

varnewElement(oldElement).clone();

jQuery).attr'id'fileId);

jQuery).before(newElement).appendTo(form);

//add data

(data{

forvariindata{

$'

}

varrequestDone=false;

// Create the request object

varxml={};

){

jQuery"ajaxSend"[xml]);

}

varuploadCallback(isTimeout){

// Wait for a response to come back

.getElementById(frameIdtry.contentWindow){

xml.responseText=io.document?io.innerHTML:null;

xml.responseXMLXMLDocument:io.contentDocumentcatch(e.handleErrorxmle(xml||isTimeout"timeout"){

requestDonetruevarstatustry{

status=isTimeout!="timeout"?"success":"error"// Make sure that the request was successful or notmodified

(status"error"// process the data (runs the xml through httpData regardless of callback)

vardata.uploadHttpData(xml.dataType.success// ifa local callback was specified,fire it and pass it the data

s.success(datastatus};

// Fire the global callback

jQuery"ajaxSuccess"};

}else{

jQuerystatus}

){

status;

jQuery// The request was completed

jQuery"ajaxComplete"};

// Handle the global AJAX counter

!--jQuery"ajaxStop"};

.complete){

s(xml};

jQuery).unbind();

setTimeout(){

).remove();

}},100);

xml};

// Timeout checker

.timeout>0){

setTimeout(){(!requestDone){uploadCallback);}},0)">.timeout+formId'action'.url'method''POST''target'frameId.encoding){

form.encoding'multipart/form-data'{

form.enctype}

jQuery).submit();

){

jQuery/*if(window.attachEvent){

document.getElementById(frameId).attachEvent('onload',uploadCallback);

}

else{

document.getElementById(frameId).addEventListener('load',uploadCallback,false);

} */

jQuery+frameId).load(uploadCallbackreturn{abortfunction(){}};

uploadHttpData(rtype!type;

data=type"xml"||data?r:r.responseText// ifthe type is "script",eval it in global context

(type"script".globalEval(data}

// Get the JavaScript object,ifJSON is used.

"json"){

data=r;

varstart=data.indexOf">"(start!=-1varend"

data.substringendeval"data = "// evaluate scripts within html

"html""

").html).evalScripts();

}

returndata/*handleError: function( s,xml,status,e ) {

// If a local callback was specified,fire it

if ( s.error )

s.error( xml,e );

// Fire the global callback

if ( s.global )

jQuery.event.trigger( "ajaxError",[xml,s,e] );

}*/

handleErrorxhre// If a local callback was specified,fire it

if.error{

s.error.call.context||s// Fire the global callback

{

?jQuery.context:jQuery).trigger"ajaxError"[xhr}

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值