Uncaught ReferenceError: mahi is not defined
Uncaught ReferenceError: mahi is not defined
当我尝试在两个函数之间传递值时收到错误消息
这是一个错误“Uncaught ReferenceError: mahi is not defined” 我已经在第 121 行定义并分配了它,但仍然面临错误
function encode() {
var selectedfile = document.getElementById("cimg").files;
if (selectedfile.length > 0) {
var imageFile = selectedfile[0];
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
var srcData = fileLoadedEvent.target.result;
window.mahi = srcData; // here i have been defined variable as mahi
console.log(mahi) // here is variable work
}
fileReader.readAsDataURL(imageFile);
}
}
console.log(mahi) //here is a error "Uncaught ReferenceError: mahi is not defined" i have it defined and asigned at line no 121 stilli am facing error
因为当您在 encode()
之外调用 console.log(mahi)
时,变量尚未声明。
当我尝试在两个函数之间传递值时收到错误消息 这是一个错误“Uncaught ReferenceError: mahi is not defined” 我已经在第 121 行定义并分配了它,但仍然面临错误
function encode() {
var selectedfile = document.getElementById("cimg").files;
if (selectedfile.length > 0) {
var imageFile = selectedfile[0];
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
var srcData = fileLoadedEvent.target.result;
window.mahi = srcData; // here i have been defined variable as mahi
console.log(mahi) // here is variable work
}
fileReader.readAsDataURL(imageFile);
}
}
console.log(mahi) //here is a error "Uncaught ReferenceError: mahi is not defined" i have it defined and asigned at line no 121 stilli am facing error
因为当您在 encode()
之外调用 console.log(mahi)
时,变量尚未声明。