Book Image

PhoneGap 4 Mobile Application Development Cookbook

Book Image

PhoneGap 4 Mobile Application Development Cookbook

Overview of this book

Table of Contents (19 chapters)
PhoneGap 4 Mobile Application Development Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

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:

  1. Firstly, create a new PhoneGap project named ajax by running the following line:

    phonegap create ajax com.myapp.ajax ajax
    
  2. Add the devices platform. You can choose to use Android, iOS, or both:

    cordova platform add ios
    cordova platform add android
    
  3. Open www/index.html and clean up the unnecessary elements. Include a reference to the XUI JavaScript library and the Cordova JavaScript file.

  4. Create a new script tag block before the closing body tag with an empty onLoad function, which we'll populate shortly.

  5. Add an XUI on event handler to run the onLoad method once the DOM has fully loaded...