Page 1 of 1

read a local file

PostPosted: Wed Sep 30, 2015 3:06 pm
by David de Argentina
hI all,

My app needs to get some values from a local text file called data.txt.

I had tryed some ways to do. Most relevant are:

a)
Code: Select all
$.get('data.txt', function(data) {
  alert(data);
}, "text");


b)
Code: Select all
var oMyBlob = new Blob(["data.txt"], {type : 'text/html'});
var reader = new FileReader();
  reader.onload = function(){
  var text = reader.result;
  var node = document.getElementById('output');
  node.innerText = text;
  console.log(reader.result.substring(0, 200));
}
reader.readAsText(oMyBlob);


But nothing worked.
a) has a cross-domain problem (no webbrowser at phone -> no possible php file...)
b) returns the filename (data.txt)

Any ideas ?

Thanks in advance,
David de Argentina

Re: read a local file

PostPosted: Wed Sep 30, 2015 6:27 pm
by Neosoft Support

Re: read a local file

PostPosted: Wed Sep 30, 2015 7:18 pm
by David de Argentina
Thanks Dave,

Same errors (in both links) :

"XMLHttpRequest cannot load file:///C:/Listener/Filereader/data.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource."

I think i must go for another way.

Re: read a local file

PostPosted: Mon Jan 23, 2017 6:30 am
by yanzco
also exploring in neoappbuilder

anyone know how to save some variables to a txt file?..
and read txt file content to a variable
?

Re: read a local file

PostPosted: Wed Jan 25, 2017 7:20 pm
by Neosoft Support
See the two links above.

Also try NAB's built-in Local Storage actions if you just want a simple method of saving data between sessions.

Re: read a local file

PostPosted: Wed Jan 25, 2017 7:41 pm
by yanzco
i was trying to make an simple app for android..
and want to try saving a txt file to the sdcard.. or some folder in android that is accessible..

read and write, if possible..