Closed Kepron closed 2 years ago
I figured out. This happens because of Promise. Here is the working code.
imageCompression(original_file, options)
.then(function (compressedFile) {
console.log('compressedFile instanceof Blob', compressedFile instanceof Blob); // true
console.log(`compressedFile size ${compressedFile.size / 1024 / 1024} MB`); // smaller than maxSizeM
var file_Type = compressedFile.type.split('/').pop().toLowerCase();
var filedata = new FormData();
filedata.append('game', game);
filedata.append('data', image_type);
filedata.append('input_val', "image");
filedata.append('file', compressedFile);
filedata.append('file_type', file_Type);
ajaxpost(filedata);
})
.catch(function (error) {
console.log(error.message); // output: I just want to stop
});
function ajaxpost (dataForm) {
$.ajax({
// some ajax code
});
}
I'm trying to use the script with ajax but failed. I'm still a beginner with Javascript. Where am I doing wrong?
https://jsfiddle.net/rd8f6vqu/2/