-
-
Save shuiRong/f2bb34d48046bcd5eb6d1307a2713e97 to your computer and use it in GitHub Desktop.
JS,Ajax上传图片(二进制数据)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('...').on('change', function () { | |
var filearr = []; | |
var myfile = document.getElementById('file'); | |
var files = this.files; | |
var formData = new FormData(); | |
for (var i = 0; i < files.length; i++) { | |
//提交时,我们把filearr中的数据遍历一遍 | |
console.log(i, files[i]); | |
formData.append('file', files[i]); //用append添加到formData中 | |
} | |
$.ajax({ | |
url: '', | |
type: 'POST', | |
data: formData, | |
cache: false, //不设置缓存 | |
processData: false, // 不处理数据 | |
contentType: false, // 不设置内容类型 | |
success: function(res) { | |
$('#head-img-base64').val(res); | |
}, | |
error: function(e) { | |
console.log(e); | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment