国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js ajaxfileupload.js上傳報錯的解決方法

2019-11-20 10:09:25
字體:
來源:轉載
供稿:網友

相信大家在工作中經常用到文件上傳的操作,因為我是搞前端的,所以這里主要是介紹ajax在前端中的操作。代碼我省略的比較多,直接拿js那里的

$.ajaxFileUpload({   url:'www.coding/mobi/file/uploadSingleFile.html',//處理圖片腳本   secureuri :false,   fileElementId :'image2',//file控件id。就是input type="file" id="image2"   dataType : 'json',   success : function (data, status){    console.log(data);   },   error: function(data, status, e){    alert(e);   }   })

按照教程,這樣子上傳的話是沒有問題的,可是它一直有一個報錯。報的是什么錯有點忘了,不好意思 ,因為用完很久才記得補回這篇文章,但是要修改它的源碼,那個錯誤就可以解決了 

它源碼的最后一段是這樣子的

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; }

將這一段改為這樣子

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" ){  // 因為json數據會被<pre>標簽包著,所以有問題,現在添加以下代碼,  // update by hzy  var reg = /<pre.+?>(.+)<//pre>/g;   var result = data.match(reg);  result = RegExp.$1;  // update end  data = $.parseJSON(result);  // 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 報這錯jQuery.handleError is not a function

版本1.4.2之前的版本才有handlerError方法,例子里使用的Jquery是1.2的,解決方法:

為了能夠繼續使用ajaxfileupload上傳我們的附件,只好將下面代碼拷進我們的項目中的ajaxfileupload.js文件中

handleError: function( s, xhr, status, e )  {   // If a local callback was specified, fire it     if ( s.error ) {      s.error.call( s.context || s, xhr, status, e );     }      // Fire the global callback     if ( s.global ) {      (s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );     }  } 

更多精彩內容請參考專題《ajax上傳技術匯總》,《javascript文件上傳操作匯總》《jQuery上傳操作匯總》進行學習。

以上就是面對ajaxupload.js上傳報錯問題的解決方法,希望能幫助大家解決困難,也希望大家繼續關注武林網更多精彩內容。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 手游| 高邑县| 仁化县| 威信县| 东莞市| 西平县| 华宁县| 建水县| 申扎县| 永寿县| 攀枝花市| 格尔木市| 蒙自县| 九台市| 甘孜| 泰安市| 高雄市| 信阳市| 苗栗县| 土默特左旗| 玉田县| 长顺县| 乌兰县| 甘德县| 达拉特旗| 唐河县| 汝州市| 禹城市| 巴塘县| 普宁市| 辽中县| 大田县| 呼伦贝尔市| 许昌市| 岳阳县| 佛学| 礼泉县| 兴仁县| 柘荣县| 万安县| 莱州市|