$.ajaxFileUpload上传文件出现错误-错误总结

本文档详细解析了使用AjaxFileUpload.js插件时遇到的常见错误,包括加载顺序错误、运行时错误及成功回调无法正常触发等问题,并提供了具体的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、 加载报错: ajaxfileupload.js:1 Uncaught ReferenceError: jQuery is not defined
上传报错: Uncaught TypeError: $.ajaxFileUpload is not a function
原因: jquery.js,ajaxfileupload.js加载顺序不正确,应先加载 jquery.js,再加载ajaxfileupload.js

<script type="text/javascript" src="jquery.js"></script>
<script src="ajaxfileupload.js" type="text/javascript"></script>

2、 运行时报错: jQuery.handleError is not a function
原因: ajaxfileupload.js插件中使用低版本jquery,版本1.4.2之前的版本才有handlerError方法,例子里使用的Jquery是1.2的,需手动添加该方法

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

3、 执行成功后,始终指向error方法处理,无法执行sucess方法
原因: 这个是由于ajaxfileupload.js 处理返回data的时候,没有考虑后台返回的是字符串的问题,data数据被加了pre标签了。。。

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")
data=data.replace("<pre>","").replace("</pre>",""); //如果返回的是字符串(JSON格式字符串),去除pre标签
data=eval('(' + data+ ')'); // evaluate scripts within html
return data;
if (type == "html")
jQuery("<div>").html(data).evalScripts();
return data;
}

转载于:https://blog.51cto.com/13660675/2089037

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值