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
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
-
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>
}