Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Multiple XHRs

Hi,

i have problems to create multiple xhrs.
In my case i want to download serveral images and save them.
I found this example in KitchenSink


var xhr = Titanium.Network.createHTTPClient();

xhr.onload = function()
{
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'ti.png');
f.write(this.responseData);
imageView.url = f.nativePath;
};

xhr.open('GET','https://www.appcelerator.com/wp-content/uploads/2009/06/titanium_desk.png');

xhr.send();


now i want to do that for different files.

Does anybody know a good way to do this?

Best regards

Roland

— asked June 1st 2010 by Roland Beisel
0 Comments

2 Answers

  • > i have problems to create multiple xhrs

    What would the problem actually be?

    > In my case i want to download serveral images and save them

    so you would have to make several XHR calls for the several images… if it's something you'll be doing often, i'd suggest making a JavaScript function out of the above example code where you pass in the URL of the image

    — answered June 1st 2010 by Stephen Gilboy
    permalink
    0 Comments
  • I made it the solution that you create a function name ex: save(data,file) and put the f.write in this function is work well .

    var xhr = Titanium.Network.createHTTPClient();
    xhr.onload = function() { var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'ti.png'); };<br>
    save(this.responseData,f);<br>
    xhr.open('GET','https://www.appcelerator.com/wp-content/uploads/2009/06/titanium_desk.png');
    xhr.send();

    Function save(data,f){<br>
    f.write(data); imageView.url = f.nativePath;<br>
    }

    — answered June 15th 2011 by guellai farid
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.