上传文件-jq

var formFile = new FormData();
formFile.append("[file]", fileObj);
formFile.append("type", uploadKey.type);
formFile.append("contentType", uploadKey.contentType);
formFile.append("contentParser", uploadKey.contentParser);
formFile.append("ignore1stLine", uploadKey.ignore1stLine);
formFile.append("charset", uploadKey.charset);
formFile.append("key", uploadKey.key);

$.ajax({
type:'POST',
url: 'http://59.108.70.66:8080/api/project/'+$nps$.portal.projectInfo.data._id+'/collection/'+oid+'/push',
processData: false,
contentType: false,
enctype:'multipart/form-data',
data:formFile
}).done(function(results){
$nps$.showMsg({
title: $nps$.portal.lang.tipText,
msg: '上传成功,请返回!',
300,
bbar: {confirm: true},
confirmclick: function()
{
win.hide();
},
scope: this
});
})

原文地址:https://www.cnblogs.com/stevenzhangcy/p/14548369.html