Jquery.mobile $.ajax complete gets called repeatedly

Jquery.mobile $.ajax complete gets called repeatedly

I'm using jquery.mobile-1.1.0.min.js and cordova-2.0.0.js (phonegap).

In my setup for my $.ajax call I set my params like this:

  1.       success: onFetchOK,   // saves everything to the database
          complete: function(jqXHR, textStatus) {
              // show everything in the database
              showAllHeaders();
          },
          error: function(xhr, textStatus, errorThrown) {
              alert("onFetchFailure: There was an error retrieving messages: \n"
                    +"xhr: " + xhr.statusText
                    +"\nstatus: " +textStatus
                    +"\nerror: " +errorThrown.message);
              $('#fetch-result').html(textStatus);
          },










The function onFetchOK gets 18 message headers back from the server, each message header has an id, subject and a date/time and these get stored in the webdb using the phonegap webdb storage API.

If I drop and recreate the message table and run the app fresh, the ajax complete: function gets called once for each of the 18 messages I receive so 342 message headers gets displayed (18x18+18).

No where in my code other than this one $.ajax complete: does showAllHeaders(); get called.

I placed an alert inside the showAllHeaders() and that alert gets triggered 19 times.

To narrow this down further I placed a loop counter inside my $.ajax success: onFetchOK() like this:

  1.     var loopCount = 0;
        // process each message
        $.each(json.messages, function(index, msg)
        {       
            // save each alert before displaying it
            webdb.addAlert(msg.msg_id, msg.title, msg.when);
            loopCount++;
        });
        alert("loopCount = " +loopCount);







When this alert is called it shows "loopCount = 18" and this is called/displayed only once.

If I exit the app, reload it and no new messages are pulled from the server then 18 message headers are displayed, which is exactly as it should be.

So, it appears that my complete: function() is being called repeatedly... once as it should and then 18 more times (effectively once for each message header retrieved).

Anyone have any idea why this would be?