使用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 = 'ab