我正在开发一个移动应用程序,我想在内存卡中下载一个文件。我有以下代码,但它无法正常工作,任何人都可以建议我为什么?
function dwnload()
{ alert('in1');
var fname=$("#filename").val();
alert(fname);
document.addEventListener('deviceready',function(){
window.requestFileSystem(LocalFileSystem.PERSISTENT,0,gotFS,fail);
}, false);
function gotFS(fileSystem){
fileSystem.root.getfile(fname + '.csv',{create: true,exclusive: false}, gotFileEntry, fail);
alert('in gotFS');
}
function gotFileEntry(fileEntry){
fileEntry.createWriter(gotFileWriter, fail);
alert('in gotFileEntry');
}
function gotFileWriter(writer)
{ alert('in gotFileWriter');
var text_wrt=$("#filetxt").val();
writer.write(text_wrt);
writer.onwriteend= function(evt)
{
$('#status').text('File Was saved Successfully');
}
}
function fail(error)
{
$('#status').text('File Save Error' +error.code);
}
}
我获取info.from用户的html代码如下,一旦我提交下面的表单,然后调用上面的函数,我的函数下载文件是否有任何错误。
<h1>Example</h1>
<form onsubmit="return dwnload();">
File name:<input type="text" id="filename" name="filename" placeholder="Enter Name of File" />
<div id="status"></div>
<p><!-- <A HREF="#" onclick="dwnload();" data-ajax="false">Local File System</A></p> -->
File Text:<input type="text" id="filetxt" name="filetxt" placeholder="Enter Something" />
<BR>
<input type="submit" name="submit" id="submit" value="submit" data-ajax="false"></>
</form>