一、ajaxfileupload在新版的jQuery中会报jQuery.handleError is not a function

解决办法:

在Ajaxfileupload.js中追加方法:

handleError: function (s, xhr, status, e) {if (s.error) {s.error.call(s.context || s, xhr, status, e);}if (s.global) {(s.context ? jQuery(s.context) : jQuery.event).trigger("ajaxError", [xhr, s, e]);}
}

二、ajaxFileUpload上传文件返回json无法解析

解决办法:

在uploadHttpData中修改type == "json"

if ( type == "json" ){data = jQuery.parseJSON(jQuery(data).text());
}

ajaxFileUpload 全部代码为:


jQuery.extend({createUploadIframe: function(id, uri){//create framevar frameId = 'jUploadFrame' + id;if(window.ActiveXObject) {if($.support.leadingWhitespace){var io = document.createElement('iframe');io.id = frameId;io.name = frameId;}else{var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');if(typeof uri== 'boolean'){io.src = 'javascript:false';}else if(typeof uri== 'string'){io.src = uri;}}}else {var io = 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);return io},createUploadForm: function(id, fileElementId){//create formvar formId = 'jUploadForm' + id;var fileId = 'jUploadFile' + id;var form = $('<form  action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');var oldElement = $('#' + fileElementId);var newElement = $(oldElement).clone();$(oldElement).attr('id', fileId);$(oldElement).before(newElement);$(oldElement).appendTo(form);//set attributes$(form).css('position', 'absolute');$(form).css('top', '-1200px');$(form).css('left', '-1200px');$(form).appendTo('body');return form;},ajaxFileUpload: function(s) {// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout     s = jQuery.extend({}, jQuery.ajaxSettings, s);var id = s.fileElementId;var form = jQuery.createUploadForm(id, s.fileElementId);var io = jQuery.createUploadIframe(id, s.secureuri);var frameId = 'jUploadFrame' + id;var formId = 'jUploadForm' + id;// Watch for a new set of requestsif ( s.global && ! jQuery.active++ ){jQuery.event.trigger( "ajaxStart" );}var requestDone = false;// Create the request objectvar xml = {}if ( s.global )jQuery.event.trigger("ajaxSend", [xml, s]);// Wait for a response to come backvar uploadCallback = function(isTimeout){var io = 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;}else if(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 == "timeout"){requestDone = true;var status;try {status = isTimeout != "timeout" ? "success" : "error";// Make sure that the request was successful or notmodifiedif ( status != "error" ){// process the data (runs the xml through httpData regardless of callback)var data = jQuery.uploadHttpData( xml, s.dataType );// If a local callback was specified, fire it and pass it the dataif ( s.success )s.success( data, status );// Fire the global callbackif( s.global )jQuery.event.trigger( "ajaxSuccess", [xml, s] );} elsejQuery.handleError(s, xml, status);} catch(e){status = "error";jQuery.handleError(s, xml, status, e);}// The request was completedif( s.global )jQuery.event.trigger( "ajaxComplete", [xml, s] );// Handle the global AJAX counterif ( s.global && ! --jQuery.active )jQuery.event.trigger( "ajaxStop" );// Process resultif ( 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}}// Timeout checkerif ( s.timeout > 0 ){setTimeout(function(){// Check to see if the request is still happeningif( !requestDone ) uploadCallback( "timeout" );}, s.timeout);}try{// var io = $('#' + frameId);var form = $('#' + formId);$(form).attr('action', s.url);$(form).attr('method', 'POST');$(form).attr('target', frameId);if(form.encoding){form.encoding = 'multipart/form-data';}else{form.enctype = 'multipart/form-data';}$(form).submit();} catch(e){jQuery.handleError(s, xml, null, e);}if(window.attachEvent){document.getElementById(frameId).attachEvent('onload', uploadCallback);}else{document.getElementById(frameId).addEventListener('load', uploadCallback, false);}return {abort: function () {}};},uploadHttpData: function( r, type ) {var data = !type;data = type == "xml" || data ? r.responseXML : r.responseText;// If the type is "script", eval it in global contextif ( type == "script" )jQuery.globalEval( data );// Get the JavaScript object, if JSON is used.if ( type == "json" ){data = jQuery.parseJSON(jQuery(data).text());// eval( "data = " + data );}// evaluate scripts within htmlif ( type == "html" )jQuery("<div>").html(data).evalScripts();//alert($('param', data).each(function(){alert($(this).attr('value'));}));return data;},handleError: function (s, xhr, status, e) {if (s.error) {s.error.call(s.context || s, xhr, status, e);}if (s.global) {(s.context ? jQuery(s.context) : jQuery.event).trigger("ajaxError", [xhr, s, e]);}},
})

三、在上传文件时,不能传参问题

1、修改createUploadForm(1)修改createUploadForm: function(id, fileElementId, data)(2)在$(oldElement).appendTo(form);下添加代码
if (data) {for (var i in data) {$('<input type="hidden" name="' + i + '" value="' + data[i] + '" />').appendTo(form);}}2、修改ajaxFileUpload(1)var form = jQuery.createUploadForm(id, s.fileElementId, s.data);

ajaxfileupload上传文件问题相关推荐

  1. ajaxFileUpload上传文件后提示下载的问题

    在某些版本浏览器下ajaxFileUpload上传文件会提示下载, 1:为什么? 可以观察到,即便返回 JsonResult 在返回的头中也没有任何消息体,直接理解为文本了. 2:解决方案 前端: f ...

  2. 解决ajaxFileUpload上传文件在ie浏览器中出现下载框的问题

    在开发时用到ajaxFileUpload上传文件,在ie浏览器中会出现下载框的问题,结合网上查到的资料最后解决,在此记录一下,以免以后遇到不知道怎么解决, 前端: 后台: ps:返回值有list改为j ...

  3. jQuery插件之ajaxFileUpload上传文件或图片

    我用的是这个:https://github.com/carlcarl/AjaxFileUpload 下载地址在这里:http://files.cnblogs.com/files/kissdodog/a ...

  4. jQuery的ajaxFileUpload上传文件插件刷新一次才能再次调用触发change

    关于用ajaxfileupload时,遇到一个要刷新一次页面才能再次上传,用live()方法来绑定 file表单 的change事件就能够解决,直接$("xxx").change( ...

  5. ajaxfileupload 返回值_用ajaxFileUpLoad上传文件不能正确取得返回值的问题

    c++ eof()函数 C++ eof()函数可以帮助我们用来判断文件是否为空,抑或是判断其是否读到文件结尾.在这里我们将会对其进行详细的介绍. C++编程语言中的很多功能在我们的实际应用中起着非常大 ...

  6. ajaxFileUpload plugin上传文件 chrome、Firefox中出现SyntaxError:unexpected token

    使用ajaxFileUpload上传文件时遇到的一些问题,原本在本地用IE8测试一切正常.. 1.然后QA用Chrome测试之后说不能上传文件,报错(文件名获取) HTML 代码: <table ...

  7. jq ajax异步上传文件,jQuery插件ajaxFileUpload异步上传文件

    AjaxFileUpload.js并不是一个很出名的插件,只是别人写好的放出来供大家用,原理都是创建隐藏的表单和iframe然后用JS去提交,获得返回值. 当初做了个异步上传的功能,选择它因为它的配置 ...

  8. ajaxfileupload 返回值_ajaxfileupload上传文件,返回json数据报错的问题。

    在使用ajaxfileupload上传文件的时候,文件上传成功了,但是返回的json数据一直解析不了.一直提示:Resource interpreted as Document but transfe ...

  9. [原创]使用ajaxFileUpload.js上传文件时附带额外参数。

    最近公司的一个项目涉及到导入Excel的功能,于是就想到用ajaxFileUpload来实现上传文件,因为用过很多次了,网上也有很多文章介绍.使用方法不表.但是在附带参数这个环节卡住了:文件可以上传到 ...

最新文章

  1. 算法----单链表反转
  2. python 字符串前加r b u f 含义
  3. DL之随机性:理解和探究采用深度学习算法预测时导致多次运行结果不一致的问题
  4. SAP UI5 xml view content parse
  5. php+使用go编译,golang如何编译
  6. es6 获取对象的所有值_前端开发必备 - ES6 新特性之 Set和Map数据结构
  7. python多进程 保活_老板,你这个爬虫保活吗?
  8. OOAD理论知识小结
  9. Linux 上免费的视频转换器FFmpeg
  10. Android Layout
  11. 智能制造+机器视觉技术培训研讨会
  12. 栈溢出学习(四)之Hijack GOT
  13. 阿里云centos环境之vsftpd安装(十五)
  14. origin画图对图片进行缩放时,如何不让文字一同缩放?
  15. 用 Python 解数独(Sudoku)
  16. Linux日常运维管理技巧(二)
  17. 开关电源IC的选择要求
  18. K210入门-裸机开发(九)之IIS功放扬声器小喇叭(SD卡+fat文件系统)_只能wav格式(用的wav解码器)
  19. java 就业前景 ppt_Java 利用POI操作PPT
  20. ffmpeg 实现多宫格效果,视频拼接合成

热门文章

  1. Wal-mart沃尔玛验厂有哪些内容 ?
  2. 2021-03-13 15:41:23.367561: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could no
  3. pki ca基础概念
  4. 会CAD,一点3D和PS,请问可以找什么工作?
  5. gdufe acm 1361 校庆抽奖
  6. 【转】佛家的133个经典哲理转载 分享该日志 评论 举报
  7. 解决挖矿病毒占用高cpu(sysupdate、networkservice)
  8. 麓言科技UI动效设计大全,设计不再愁
  9. android menuitem 字体颜色,android-如何设置MenuItem的图标颜色?
  10. 以太网PHY寄存器分析【转】