I’m currently developing an app mainly for self-education purposes and since I’m still not completely used to js I could use some help for my problem:
In my app I’m using a Javascript library (jqMobi) which is used for DOM manipulation, page transitions, ajax calls etc and I’m also using phonegap to access device features such as the geolocation.
When I start up my app I want to get the geolocation of the device, send an ajax (jsonp) request to my server (including the geolocation of the device) which returns an array of JSON objects which I will use to build up a list.
Before I can get the geolocation I need to wait for phonegap to load. And before using jqMobi to make the ajax call and handle the response I need to wait for it to load as well.
So I basically have to events im listening to
document.addEventListener("DOMContentLoaded",execute_this,false); //jqMobi is now ready
document.addEventListener("deviceready", execure_sth, false); //Phonegap is now ready
How do I execute a function as soon as both of these events have fired and not before?
If I’d use jQuery I’d make use of its $.Deferred objects and its When … Then Function but since I don’t have access to these I’m looking for an alternative.
Try this,