一、var formser = new FormData($('#searchForm')[0]);//獲取表單的參數
formser.append("test",test)//可增長請求的參數
二、 var formser=$('#dataForm').serialize();
注意:serialize只能序列化表單中的數據 ,好比文本框等input select等的數據,可是對於文件,好比文件上傳,沒法實現 ,須要使用FormDatajquery
例:ajax
<form id="tf" method="post" action="${ctxPath}/mobile/xxx.do" enctype="multipart/form-data">
<input type="file" name="file" id="file1_0" value=""
accept="image/jpg,image/jpeg,image/png,image/gif,image/bmp"
onchange="imgChange('z_photo1','z_file1','file1_0');"/>
</form>
$.ajax({
type: 'POST',
data: uploadFormData,
url: '/Artical/Publist',//TypeError: 'append' called on an object that does not implement interface FormData.
processData: false, //processData 默認爲false,當設置爲true的時候,jquery ajax 提交的時候不會序列化 data,而是直接使用data
contentType: false, //https://segmentfault.com/a/1190000007207128(contentType詳解)segmentfault
//這兩個參數若是不寫,則會報紅色出的錯誤
async: false,
success: function (data) {
if (typeof (data) == undefined) {
alert("用戶信息已丟失,請從新登陸!");app
window.parent().location.href = "/Account/Login";
}
if (data.ErrorMsg == "") {
alert('美文發佈成功!');
} else { alert(data.ErrorMsg); }
}
});async