ajaxFileUpload 报这错jQuery.handleError is not a func

<p>现在大家至少也在用jquery1.9以上的版本,ajaxfileupload的版本早就不更新了,大家可以下载看:地址这里,它例子里使用的Jquery是1.2的,好老呀。。。这个问题,我以前开发过程中遇过,网上说经测试(我是没测试),是版本1.4.2之前的版本才有handlerError方法,之后就不存在了,(你存在,我深深的脑海里。。。),为了能够继续使用ajaxfileupload上传我们的附件,只好将代码拷进我们的项目中的ajaxfileupload.js文件中,如下:</p><pre class="brush:java;toolbar:false">handleError:function(s,xhr,status,e){ //Ifalocalcallbackwasspecified,fireit if(s.error){ s.error.call(s.context||s,xhr,status,e); } //Firetheglobalcallback if(s.global){ (s.context?jQuery(s.context):jQuery.event).trigger(&quot;ajaxError&quot;,[xhr,s,e]); } } ----ajaxfileupload.js文件---- jQuery.extend({ handleError:function(s,xhr,status,e){ //Ifalocalcallbackwasspecified,fireit if(s.error){ s.error.call(s.context||s,xhr,status,e); } //Firetheglobalcallback if(s.global){ (s.context?jQuery(s.context):jQuery.event).trigger(&quot;ajaxError&quot;,[xhr,s,e]); } }, createUploadIframe:function(id,uri) { //createframe varframeId=&#39;jUploadFrame&#39;+id; if(window.ActiveXObject){ vario=document.createElement(&#39;&lt;iframeid=&quot;&#39;+frameId+&#39;&quot;name=&quot;&#39;+frameId+&#39;&quot;/&gt;&#39;); if(typeofuri==&#39;boolean&#39;){ io.src=&#39;javascript:false&#39;; } elseif(typeofuri==&#39;string&#39;){ io.src=uri; } } else{ vario=document.createElement(&#39;iframe&#39;); io.id=frameId; io.name=frameId; } io.style.position=&#39;absolute&#39;; io.style.top=&#39;-1000px&#39;; io.style.left=&#39;-1000px&#39;; document.body.appendChild(io); returnio }, createUploadForm:function(id,fileElementId) { //createform varformId=&#39;jUploadForm&#39;+id; varfileId=&#39;jUploadFile&#39;+id; varform=$(&#39;&lt;formaction=&quot;&quot;method=&quot;POST&quot;name=&quot;&#39;+formId+&#39;&quot;id=&quot;&#39;+formId+&#39;&quot;enctype=&quot;multipart/form-data&quot;&gt;&lt;/form&gt;&#39;); varoldElement=$(&#39;#&#39;+fileElementId); varnewElement=$(oldElement).clone(); $(oldElement).attr(&#39;id&#39;,fileId); $(oldElement).before(newElement); $(oldElement).appendTo(form); //setattributes $(form).css(&#39;position&#39;,&#39;absolute&#39;); $(form).css(&#39;top&#39;,&#39;-1200px&#39;); $(form).css(&#39;left&#39;,&#39;-1200px&#39;); $(form).appendTo(&#39;body&#39;); returnform; }, ajaxFileUpload:function(s){ //TODOintroduceglobalsettings,allowingtheclienttomodifythemforallrequests,notonlytimeout s=jQuery.extend({},jQuery.ajaxSettings,s); varid=newDate().getTime() varform=jQuery.createUploadForm(id,s.fileElementId); vario=jQuery.createUploadIframe(id,s.secureuri); varframeId=&#39;jUploadFrame&#39;+id; varformId=&#39;jUploadForm&#39;+id; //Watchforanewsetofrequests if(s.global&amp;&amp;!jQuery.active++) { jQuery.event.trigger(&quot;ajaxStart&quot;); } varrequestDone=false; //Createtherequestobject varxml={} if(s.global) jQuery.event.trigger(&quot;ajaxSend&quot;,[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; }elseif(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==&quot;timeout&quot;) { requestDone=true; varstatus; try{ status=isTimeout!=&quot;timeout&quot;?&quot;success&quot;:&quot;error&quot;; //Makesurethattherequestwassuccessfulornotmodified if(status!=&quot;error&quot;) { //processthedata(runsthexmlthroughhttpDataregardlessofcallback) vardata=jQuery.uploadHttpData(xml,s.dataType); //Ifalocalcallbackwasspecified,fireitandpassitthedata if(s.success) s.success(data,status); //Firetheglobalcallback if(s.global) jQuery.event.trigger(&quot;ajaxSuccess&quot;,[xml,s]); }else jQuery.handleError(s,xml,status); }catch(e) { status=&quot;error&quot;; jQuery.handleError(s,xml,status,e); } //Therequestwascompleted if(s.global) jQuery.event.trigger(&quot;ajaxComplete&quot;,[xml,s]); //HandletheglobalAJAXcounter if(s.global&amp;&amp;!--jQuery.active) jQuery.event.trigger(&quot;ajaxStop&quot;); //Processresult 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); } },100) xml=null } } //Timeoutchecker if(s.timeout&gt;0) { setTimeout(function(){ //Checktoseeiftherequestisstillhappening if(!requestDone)uploadCallback(&quot;timeout&quot;); },s.timeout); } try { //vario=$(&#39;#&#39;+frameId); varform=$(&#39;#&#39;+formId); $(form).attr(&#39;action&#39;,s.url); $(form).attr(&#39;method&#39;,&#39;POST&#39;); $(form).attr(&#39;target&#39;,frameId); if(form.encoding) { form.encoding=&#39;multipart/form-data&#39;; } else { form.enctype=&#39;multipart/form-data&#39;; } $(form).submit(); }catch(e) { jQuery.handleError(s,xml,null,e); } if(window.attachEvent){ document.getElementById(frameId).attachEvent(&#39;onload&#39;,uploadCallback); } else{ document.getElementById(frameId).addEventListener(&#39;load&#39;,uploadCallback,false); } return{abort:function(){}}; }, uploadHttpData:function(r,type){ vardata=!type; data=type==&quot;xml&quot;||data?r.responseXML:r.responseText; //Ifthetypeis&quot;script&quot;,evalitinglobalcontext if(type==&quot;script&quot;) jQuery.globalEval(data); //GettheJavaScriptobject,ifJSONisused. if(type==&quot;json&quot;) eval(&quot;data=&quot;+data); //evaluatescriptswithinhtml if(type==&quot;html&quot;) jQuery(&quot;&lt;div&gt;&quot;).html(data).evalScripts(); //alert($(&#39;param&#39;,data).each(function(){alert($(this).attr(&#39;value&#39;));})); returndata; } })</pre>
返回顶部 留言