Working with remote data and AJAX requests
With a vast array of remote servers exposing their services as accessible APIs, you can create some truly dynamic applications by pulling and pushing data to and from external applications and providers.
How to do it...
We will use the XHR method within the XUI library to request data from a remote server, making an asynchronous call to obtain the results from a search:
Firstly, create a new PhoneGap project named
ajax
by running the following line:phonegap create ajax com.myapp.ajax ajax
Add the devices platform. You can choose to use Android, iOS, or both:
cordova platform add ios cordova platform add android
Open
www/index.html
and clean up the unnecessary elements. Include a reference to the XUI JavaScript library and the Cordova JavaScript file.Create a new
script
tag block before the closingbody
tag with an emptyonLoad
function, which we'll populate shortly.Add an XUI
on
event handler to run theonLoad
method once the DOM has fully loaded...