file上传ajax传值,ajaxfileupload传递文件及参数

jQuery.extend({

createUploadIframe:function(id,uri)

{

//createframe

varframeId='jUploadFrame'+id;

if(window.ActiveXObject){

vario=document.createElement('');

if(typeofuri=='boolean'){

io.src='javascript:false';

}

elseif(typeofuri=='string'){

io.src=uri;

else{

vario=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);

returnio

},

createUploadForm:function(id,fileElementId,data)

//createform

varformId='jUploadForm'+id;

varfileId='jUploadFile'+id;

varform=$('');

varoldElement=$('#'+fileElementId);

varnewElement=$(oldElement).clone();

$(oldElement).attr('id',fileId);

$(oldElement).before(newElement);

$(oldElement).appendTo(form);

//增加文本参数的支持

if(data){

for(variindata){

$('').appendTo(form);

//setattributes

$(form).css('position','absolute');

$(form).css('top','-1200px');

$(form).css('left',250); line-height:18px"> $(form).appendTo('body');

returnform;

ajaxFileUpload:function(s){

//TODOintroduceglobalsettings,allowingtheclienttomodifythemforallrequests,notonlytimeout

s=jQuery.extend({},jQuery.ajaxSettings,s);

varid=newDate().getTime()

varform=jQuery.createUploadForm(id,s.fileElementId,s.data);

vario=jQuery.createUploadIframe(id,s.secureuri);

//Watchforanewsetofrequests

if(s.global&&!jQuery.active++)

jQuery.event.trigger("ajaxStart");

varrequestDone=false;

//Createtherequestobject

varxml={}

if(s.global)

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

//Waitforaresponsetocomeback

varuploadCallback=function(isTimeout)

vario=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;

}if(io.contentDocument)

xml.responseText=io.contentDocument.document.body?io.contentDocument.document.body.innerHTML: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;

varstatus;

try{

status=isTimeout!="timeout"?"success":"error";

//Makesurethattherequestwassuccessfulornotmodified

if(status!="error")

//processthedata(runsthexmlthroughhttpDataregardlessofcallback)

vardata=jQuery.uploadHttpData(xml,s.dataType);

//Ifalocalcallbackwasspecified,fireitandpassitthedata

if(s.success)

s.success(data,status);

//Firetheglobalcallback

jQuery.event.trigger("ajaxSuccess",85); font-weight:bold">else

status="error";

//Therequestwascompleted

jQuery.event.trigger("ajaxComplete",0); padding:0px; margin:0px; width:auto; border:0px">//HandletheglobalAJAXcounter

if(s.global&&!--jQuery.active)

jQuery.event.trigger("ajaxStop");

//Processresult

if(s.complete)

s.complete(xml,250); line-height:18px"> jQuery(io).unbind()

setTimeout(function()

{$(io).remove();

$(form).remove();

100)

xml=null

//Timeoutchecker

if(s.timeout>0)

setTimeout(function(){

//Checktoseeiftherequestisstillhappening

if(!requestDone)uploadCallback("timeout");

//vario=$('#'+frameId);

varform=$('#'+formId);

$(form).attr('action',s.url);

$(form).attr('method','POST');

$(form).attr('target',frameId);

if(form.encoding)

form.encoding='multipart/form-data';

form.enctype='multipart/form-data';

$(form).submit();

if(window.attachEvent){

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

document.getElementById(frameId).addEventListener('load',uploadCallback,85); font-weight:bold">false);

return{abort:function(){}};

uploadHttpData:function(r,type){

vardata=!type;

data=type=="xml"||data?r.responseXML:r.responseText;

//Ifthetypeis"script",evalitinglobalcontext

if(type=="script")

jQuery.globalEval(data);

//GettheJavaScriptobject,ifJSONisused.

if(type=="json")

eval("data="+data);

//evaluatescriptswithinhtml

if(type=="html")

jQuery("

").html(data).evalScripts();

//alert($('param',data).each(function(){alert($(this).attr('value'));}));

returndata;

})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值