要让ajaxfileupload兼容IE9、IE10,修改它的源码
找到以下代码
if(window.ActiveXObject) {
var io = document.createElement('');
if(typeof uri== 'boolean'){
io.src = 'javascript:false';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);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('');
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串解析为对象
public void importBuyerByExcel(@RequestParam() MultipartFile exclFile,HttpSession session,HttpServletRequest request,ModelMap map,HttpServletResponse response)
throws IOException{
response.setContentType("text/html");
response.getWriter().write(JSONObject.fromObject(map).toString());
}
后台用response返回json串的原因是中文乱码,搞了好久都没解决,无奈之下只有这样搞了
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);