I have a weird problem with Phonegap. My XMLHttpRequests fire twice; I'm using XMLHttpRequests in an app I'm developing to create a dynamic list of events to select. jQuery is also one of the libs I'm using.
Any time I use an XMLHttpRequest, either vanilla or jQuery, it does it twice, even though it should only run once. Has anyone else ran into this problem?
Some example code here:
(function(){
var request = new XMLHttpRequest();
request.open("GET", "http://{site-url-hidden-for-privacy}/events/list", true);
request.onreadystatechange = function(){
if(request.readyState == 4){
if(request.status == 200 || request.status == 0){
parse_events(JSON.parse( request.responseText ));
}
}
}
request.send();
})();
the XMLHttpResponse text is a JSON array, and parse_events simply takes that array and uses it to create a set of select options for a menu.
Does anyone know why this would fire twice, essentially creating two options for each event, when there should only be one?