Time for action – creating an HTTP request
To create an HTTP request perform the following steps:
The first step is to create an
HTTPClient
variable. For this example we will call itxhr
.var xhr = Titanium.Network.createHTTPClient();
Note
There is no return value or response from an HTML call. Unlike all other function calls, for example reading from a file, an HTML request can take quite some time to respond. It will be executed in the background while your app continues to function. You don't want your app to stop and wait for several seconds or more while the data is retrieved; the app should continue to operate while the data is being retrieved in the background. You set the HTML call up, execute the request, and then leave it to Titanium to call your code with the data when the request completes.
The
onerror
property defines the code that will be called in the event of something going wrong. This is where you define what you want to happen if the request fails. In this case we are showing...