多數瀏覽器都支持new FormData($( "#fileUploadForm")[0]),可是IE10下卻顯示
FormData未定義
//AJAX文件上傳
$.ajax({
url: path + "/fileManager/uploadFile",
type: 'post',
data: new FormData($( "#fileUploadForm")[0]),
async: true,
cache: false,
contentType: false, // 告訴jQuery不要去處理髮送的數據
processData: false, // 告訴jQuery不要去設置Content-Type請求頭
success: function (data) {
mini.hideMessageBox(messageid);
mini.confirm(data.msg ,"提示",function delConfirm(action){
window.CloseOwnerWindow();
});
},
error: function (data) {
mini.hideMessageBox(messageid);
var msg = data.msg;
if(null == msg || "" == msg || "undefined" == msg){
msg = "操做出現異常";
}
mini.confirm(msg ,"提示",function delConfirm(action){
window.CloseOwnerWindow();
});
}
});
}
怎麼辦呢?只有換一個提交策略了ajaxSubmit
$("#batchAdd").ajaxSubmit({
type: 'post',
url: path+'/sysInfo/importSysInfo',
success: function (data) {
var msssage = JSON.parse(data);
mini.alert(msssage.msg ,"提示",function ImportSysConfirm(action){
window.CloseOwnerWindow();
});
},
error: function (data) {
var msssage = JSON.parse(data);
var msg = msssage.msg;
if(null == msg || "" == msg || "undefined" == msg){
msg = "操做出現異常";
}
mini.alert(msg,"提示",function ImportSysConfirm(action){
window.CloseOwnerWindow();
});
}
});
不過這裏的時候也出現了一個問題,因爲返回的時候JSON,IE8老是要提示是否下載JSON文件
好辦取配置文件裏配一下
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value><!-- 避免IE出現下載JSON文件的狀況 -->
</list>
</property>
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<!-- 處理responseBody 裏面日期類型 -->
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />
</bean>
</property>
<!-- 爲null字段時不顯示 -->
<property name="serializationInclusion">
<value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
大功告成
來源:http://wy-2017.iteye.com/blog/2386851html