我正在努力通过ajax表单上传文件而不使用FormData。 FormData不是一个选项,因为该表单包含我与第三方进行令牌化的信用卡信息,并且我不希望将CC信息提交给我的后端。
我确实看到了这个question,我将其作为一个起点,但我对jQuery很新,并且在实施方面苦苦挣扎。
我根本没有收到var文件的提交,但其他一切都很好。我没有正确收集文件,或者我没有以正确的方式将其纳入范围?
我的upload.js文件:
var file;
$("#file").on("change", function(){
var file = this.files[0],
filename = this.files[0].name;
filesize = this.files[0].size;
//calling alert(file) provides a response of [object file]
})
function handleResponse(response) {
// fires if credit card info is successfully tokenized
if (response.status_code === 201) {
var fundingInstrument = response.cards != null ? response.cards[0] : response.bank_accounts[0];
//rest of the form inputs
var name = $('#name').val();
var contact_name = $('#contact_name').val();
var cell = $('#cell').val();
var address_1 = $('#address_1').val();
var city = $('#city').val();
var state = $('#state').val();
var zip = $('#zip').val();
var tax = $('#tax').val();
//trying to bring file var in scope
var file = file;
// ajax .post
jQuery.post(baseURL+'/contractors/edit', {
uri: fundingInstrument.href,
name: name,
contact_name: contact_name,
cell: cell,
file: file,
address_1: address_1,
city: city,
state: state,
zip: zip,
tax: tax,
file: file,
}, function(r) {
// Check backend response
if (r.status === 200) {...