我有一些问题,我想使用Ajax上传多个图像,但在上传之前,我想先将它存储到javascript数组中。我怎么能做到这一点, 我的剧本:
<img id="prepareupload" width="200" hidden="" height="200" alt="your image" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4R/YRXhpZgAATU0AKgAAAAgAEQEOAAIAAAAgAAAI5gEPAAIAAAAgAAAJBgEQAAIAAAAgAAAJJgESAAMAAAABAAEAAAEaAAUAAAABAAAJRgEbAAUAAAABAAAJTgEoAAMAAAABAAIAAAExAAIAAAAuAAAJVgEyAAIAAAAUAAAJhAITAAMAAAABAAIAAAIgAAQAAAABAAAAAAIhAAQAAAABAAAAAAIiAAQAAAABAAAAAAIjAAQAAAABAAAAAIdpAAQAAAABAAAJmIglAAQAAAABAAATMOocAAcAAAgMAAAA2gAAFEwc6gAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...BHO4YG4cj6UCFU4ygC8ctQAULAjr+VACmMrktwMc4NI0keQF78haAGAdATgk8inkiPBA/iHPrQFg8tM7wBxx9MU8YAGB67h9aBjA7AEnGMnPrSBSAxXH0oAcCWBA3DnGaaOgzwQeMUgA42gbiO2McUoQc55HU0wE2qGTdzzyD0pCHOQ3IxkGgB6lWMjDg84NHlIxyOmM8UgA5Zsjj60gBSTcR0xn6UwEZnjQs5JPQH0pd52vJ1xnFACOG2Bzk45zSsgEfGeCSfxoAQtnhgSdoHHpSZcnyyeMUAOAUEKBjnA96UMEIVvr+VAA7lZD9ABj2ocgbcAsf5ZpALG3zAOODxj0pjFlcxk/N6UAAc7Rng5O76UFsgnA9MYoAdhVi2dRnqO9IkhyiPyetMBBw5yAOD160KC4dX4OetIBS+OFCqScUoVMc5OckUANyQMHBOcGnAJztznvTAM8goRxgAmmlQcrySMcdjQApDoED7QSSMD0pjgEA4C/NjIoCx/9k=" style="border: 1px solid black; display: inline;">
不,如何将它存储到JS数组以及如何上传此图像, 谢谢..
答案 0 :(得分:1)
我认为用数组做这件事是不可能的。你应该使用FormData。
var formData = new FormData();
//Supposing you are getting them from an input file
formData.append('image', $('input[type=file]')[0].files[0]);
然后是这样的:
$.ajax({
url: 'url here',
data: formData,
// Must have this
contentType: false,
processData: false,
})