gpt4 book ai didi

html - 在 HTML5 中有什么方法可以使 Filereader 的 readAsBinaryString() 同步

转载 作者:搜寻专家 更新时间:2023-10-31 08:06:30 28 4
gpt4 key购买 nike

如何等到onload事件完成

function(){

var filedata=null;
reader.onload=function(e){
filedata=e.target.result;
};
reader.readAsBinaryString(file);

//I need code to wait till onload event handler gets completed.
return filedata;
}

最佳答案

对此的典型解决方案是分离您的代码,以便使用加载数据的部分位于一个单独的函数中,然后从事件中调用该函数。

伪代码:

function load() {
//load here
reader.onload = function(e) {
process(e.target.result);
}
}

function process(result) {
//finish working here
}

关于html - 在 HTML5 中有什么方法可以使 Filereader 的 readAsBinaryString() 同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7360187/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com