I am developing a mobile app,where i want to download a file in memory card.I have following code for this,but its not working, can anyone suggest me why??
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);
}
}
and my html code for getting info.from user is as followa,once i submit following form then it calls above function,is there any error in my function for file download.
<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>