ajaxfileupload 返回值_Ajaxfileupload 上传文件后返回response的contentType错误问题
使用ajaxFileupload上传文件,将文件内容以json方式返回显示到浏览器。
问题:返回的文件内容较小时正常,但当返回的json数据大概大于10K后,返回到浏览器后弹出保存文件对话框,无法正常显示。经过测试,如果去掉上传文件功能,可以正常返回300K的json数据。
struts2设置response contentType 为text/html。另外设置为text/plain、application/json都有这个问题。
js代码:
$.ajaxFileUpload({
url:'${ctx}/domain/Reso!uploadFile.action',
secureuri:false,
fileElementId:'file',
dataType: 'json',
success: function (json){
var data = json.data;
$(data).each(function(i){
fillRecord(data[i].host,data[i].status,data[i].type);
//fillRecord是填充页面表格
});
},
error: function (data, status, e){
alert(e);
}
})
以下是ajaxfileupload.js代码:
jQuery.extend({
createUploadIframe: function(id, uri)
{
//create frame
var frameId = 'jUploadFrame' + id;
if(window.ActiveXObject) {
var io = document.createElement('');
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 form
var formId = 'jUploadForm' + id;
var fileId = 'jUploadFile' + id;
var 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 = new Date().getTime()
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 requests
if ( s.global && ! jQuery.active++ )
{
jQuery.event.trigger( "ajaxStart" );
}
var requestDone = false;
// Create the request object
var xml = {}
if ( s.global )
jQuery.event.trigger("ajaxSend", [xml, s]);
// Wait for a response to come back
var 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 notmodified
if ( 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 data
if ( s.success )
s.success( data, status );
// Fire the global callback
if( s.global )
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
} else
jQuery.handleError(s, xml, status);
} catch(e)
{
status = "error";
jQuery.handleError(s, xml, status, e);
}
// The request was completed
if( s.global )
jQuery.event.trigger( "ajaxComplete", [xml, s] );
// Handle the global AJAX counter
if ( s.global && ! --jQuery.active )
jQuery.event.trigger( "ajaxStop" );
// Process result
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
}
}
// Timeout checker
if ( s.timeout > 0 )
{
setTimeout(function(){
// Check to see if the request is still happening
if( !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 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("
//alert($('param', data).each(function(){alert($(this).attr('value'));}));
return data;
}
})
大家帮看看可能是什么问题?谢谢!
ajaxfileupload 返回值_Ajaxfileupload 上传文件后返回response的contentType错误问题相关推荐
- ajaxfileupload 返回值_ajaxFileUpload 上传文件 以及 返回值 带 pre 标签问题
$.ajaxFileUpload({ url:'upfile.action', secureuri:false, fileElementId:'inputpath', data:{"file ...
- ajaxfileupload 返回值_ajaxfileupload上传文件,返回json数据报错的问题。
在使用ajaxfileupload上传文件的时候,文件上传成功了,但是返回的json数据一直解析不了.一直提示:Resource interpreted as Document but transfe ...
- ajaxfileupload 返回值_ajaxFileUpload上传文件成功后却无法解析服务器返回的json数据...
ajaxFileUpload是一款很好用的文件上传插件,网上也有很多关于它的版本,但在上传文件成功后想返回json数据给前台时,却会出现无法解析json数据的情况. 仔细调试发现其实在向服务器提交数据 ...
- ajaxfileupload 返回值_ajaxFileUpload上传文件返回json无法解析
最近做一个文件上传的功能,还要绑定数据传输到后台,为了不影响前端的体验,采用ajax发送请求.找了一些资料,网上的用ajaxupload这个插件. 但是无论成功还是失败都是执行的error的回调函数. ...
- 文件服务器异常 选择签名,OSS上传文件后,服务器签名验证失败
关于 OSS上传文件后,服务器签名验证失败的搜索结果 回答 指定该Header后,在响应头中也会返回该Header,OSS会对上传的Object进行加密编码存储,当这个Object被下载时,响应头中会 ...
- Spring MVC上传文件后重命名读取不显示,报错已解决(The origin server did not find a current representation for the targe)
上传文件后,重命名保存在本地,再读取时报错:The origin server did not find a current representation for the target resourc ...
- vue+elementui 同时有上传文件和批量上传文件功能,上传文件或批量上传文件后必须刷新才能再次上传文件
报错描述: 使用element-ui的上传文件组件写一个批量上传和上传文件,但是发现每次上传文件后或者批量上传文件后,不能再次上传文件或者批量上传文件.只有进入页面第一次点击上传文件或者批量上传文件才 ...
- ajaxFileUpload上传文件后提示下载的问题
在某些版本浏览器下ajaxFileUpload上传文件会提示下载, 1:为什么? 可以观察到,即便返回 JsonResult 在返回的头中也没有任何消息体,直接理解为文本了. 2:解决方案 前端: f ...
- 上传文件 后清空file
王小宾 Nothing Is Impossible! 博客园 首页 新随笔 联系 管理 随笔 - 35 文章 - 0 评论 - 8 input type file上传文件之后清空内容. 上次写过如 ...
- jquery-form中ajaxSubmit提交文件,以及解决ie9下上传文件后自动下载问题
需要引用jquery-form.js 下载地址http://plugins.jquery.com/form/ 1.之前的项目一直使用formData的方式上传文件到后台处理,但新项目要求支持ie9,i ...
最新文章
- android 指纹识别支付 secure os,Android指纹登录/指纹支付简述
- TCP/IP协议(3):数据链路层
- 索引原理,查询机制(转)
- Java内存之栈与堆
- qtcreator摄像头显示时间_屏下摄像头手机量产了,然后呢?
- Java socket中关闭IO流后,发生什么事?(以关闭输出流为例)
- angularjsl路由_AngularJS路由和模板
- oracle sga pga mysql_修改Oracle数据库SGA和PGA大小
- 面试题11. 旋转数组的最小数字
- 从Postman到ApiPost——码农闰土
- 机器学习-吴恩达-笔记-8-支持向量机
- clear:both 有高度的问题
- 周鸿祎评互联网大佬的编程能力:我能排前三,谁排第一?
- mysql 启动 配置文件,mysql启动服务配置文件编写
- lua脚本java_java操作lua脚本
- php存储富文本编辑器内容到数据库
- iOS开发之—— XCODE真机调试设备连接一直忙碌如何处理!(真机调试各种错误提示解决)...
- 基于Patachmatch的stereo matching笔记(二):《DeepPruner》
- 带掩码的自编码器MAE在各领域中的应用总结
- oracle 插入表数据时,自动生成ID