无法使用 Html5 文件 API 写入数据
我按照教程学习了有关 html5 中的文件 API
但是,当我遇到这些代码时
fs.root.getFile('log',{create:true},function(fileEntry){ fileEntry.createWriter(function(fileWriter){ fileWriter.onwriteend=function(e){ alert("end") } fileWriter.onerror=function(e){ alert("error") } var bb=new window.WebKitBlobBuilder() bb.append('hello') fileWriter.write(bb.getBlob('text/plain')) },errorHandler) },errorHandler)
我总是遇到“错误” 当我在错误事件中设置alert(e.toString())
时,它似乎是[object ProgressEvent]
,
我的浏览器是 chromium 13,
有人有一些想法吗?多谢
I followed the tutorial to learn something about the File API in html5
but,while I met these code
fs.root.getFile('log',{create:true},function(fileEntry){ fileEntry.createWriter(function(fileWriter){ fileWriter.onwriteend=function(e){ alert("end") } fileWriter.onerror=function(e){ alert("error") } var bb=new window.WebKitBlobBuilder() bb.append('hello') fileWriter.write(bb.getBlob('text/plain')) },errorHandler) },errorHandler)
I always met "error"
and while I set alert(e.toString())
in error event,it appears to be [object ProgressEvent]
,
My browser is chromium 13,
Do someone has some ideas ? Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在alert('end')之后有一个额外的'})'。请发布完整的测试用例,人们可以查看(例如在 http://jsfiddle.net/ 上),这很重要更容易帮助你。
您是否尝试记录(顺便说一句,alert() 是旧的,请使用console.log())错误事件的属性列表?它可能有
e.code
吗?虽然我不认为它会成为一个 ProgressEvent。You have an extra '})' after alert('end'). Please post the complete testcase one can check out (e.g. on http://jsfiddle.net/), it makes it much easier to help you.
Did you try to log (BTW alert() is old, use
console.log()
) the list of properties of the error event? Does it maybe have ae.code
? Although I don't think it's expected to be a ProgressEvent.我在某处读到它仅支持 chrome13+。请检查一下
I read somewhere that it supports the chrome13+ only. please check it
您的文件编写器可能会因多种原因而失败。以下代码可能会帮助您确定是哪一个:
your filewriter could be failing for any number of reasons. the following code might help you determine which one: