Skip to content

Instantly share code, notes, and snippets.

@khajer
Created August 16, 2011 02:53
Show Gist options
  • Select an option

  • Save khajer/1148352 to your computer and use it in GitHub Desktop.

Select an option

Save khajer/1148352 to your computer and use it in GitHub Desktop.
read file from xhr and write on system
var xhr = Titanium.Network.createHTTPClient();
xhr.open("GET","http://www.yourdomain.com/test.txt");
xhr.onload = function(){
statusCode = xhr.status;
if(statusCode == 200)
{
var doc = this.responseText;
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'test.txt');
f.write(doc);
}
};
xhr.send();
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'test.txt');
var contents = f.read();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment