日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ajax文件上传报400,js ajaxfileupload.js上传报错的解决方法

發布時間:2024/10/8 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ajax文件上传报400,js ajaxfileupload.js上传报错的解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

相信大家在工作中經常用到文件上傳的操作,因為我是搞前端的,所以這里主要是介紹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("

").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數據會被

標簽包著,所以有問題,現在添加以下代碼,

// update by hzy

var reg = /

(.+)/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("

").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] );

}

}

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

總結

以上是生活随笔為你收集整理的ajax文件上传报400,js ajaxfileupload.js上传报错的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。