Base64字符串需要发送到ajax请求,但是问题在于,当函数完成该部分时,应该获取blob对象的那部分将在随后返回空值给ajax请求! >
我需要这段代码的一部分,以便网络能够记录音频并将此音频存储在数据库中!我还将代码的一部分上传到遇到错误的地方。在此先感谢您,因为如果有任何帮助,我们将为您提供多种解决方法?
图像1中附加了代码错误
}
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
var second_function = function getBlob(){
//var b = document.querySelector("audio").getAttribute("src");
return new Promise(resolve => {
var bl = blobFile();
var reader = new FileReader();
reader.readAsDataURL(bl);
console.log("Entered second function");
var base64data = reader.result;
console.log(base64data);
resolve = base64data;
alert(resolve);
});
}
var async_funct = async function(){
const second_promise= await second_function();
alert(second_promise);
}
function myFunction(){
$.ajax({
url: 'extra_question',//'extra_question?sectionId=1',
type: "POST",
data: '{"answer" : "Your answer", "voice": "Your voice here ", "questionId": 48}', //$("#sectionId").val(),//getBlob(),
processData: false,
contentType: false,
contentType: 'application/json',
success: function (result) {
window.location.href = 'other_question?sectionId=2';
},
error: function (error) {
console.log("This is :" + $("#sectionId").val());
console.log(error);
}
});
}
function getAnswers(){