要让ajaxfileupload兼容IE9、IE10,修改它的源码
找到以下代码
if(window.ActiveXObject) {
var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
if(typeof uri== 'boolean'){
io.src = 'javascript:false';<pre name="code" class="javascript">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);<pre code_snippet_id="1584425" snippet_file_name="blog_20160222_2_1150741" name="code" class="javascript">io.src = uri; } }
替换为
if(window.ActiveXObject) {
if(jQuery.browser.version=="9.0" || jQuery.browser.version=="10.0"){
var io = document.createElement('iframe');
io.id = frameId;
io.name = frameId;
}else if(jQuery.browser.version=="6.0" || jQuery.browser.version=="7.0" || jQuery.browser.version=="8.0"){
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;
}
}
}
如果只是做这样的修改,在IE下还是会有各种问题,你应该这样配置
前台
$.ajaxFileUpload
({
url:'',
secureuri:false,
fileElementId:'exclFile',
dataType: 'text',
success: function (data, status)
{
data=JSON.parse(data);
secureuri:false解决iframe的跨域问题,dataType使用text而不是json是因为在springmvc下的中文乱码问题,需要JSON.parse(data)将json串解析为对象
java后台
public void importBuyerByExcel(@RequestParam() MultipartFile exclFile,HttpSession session,HttpServletRequest request,ModelMap map,HttpServletResponse response)
throws IOException{
<span style="white-space:pre"> </span>response.setContentType("text/html");
<span style="white-space:pre"> </span>response.getWriter().write(JSONObject.fromObject(map).toString());
}
后台用response返回json串的原因是中文乱码,搞了好久都没解决,无奈之下只有这样搞了
让ajaxfileupload支持多个参数上传,找到以下代码
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);
替换为
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, s.tag_name, s.tag_link, s.tag_sort, s.tag_status, s.tag_id);