Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery.mobile $.ajax complete gets called repeatedly
    primarykey
    data
    text
    <p>I'm using jquery.mobile-1.1.1.min.js and cordova-2.0.0.js (phonegap).</p> <p>In my setup for my $.ajax call I set my params like this:</p> <pre><code> 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); }, </code></pre> <p>The function onFetchOK gets 18 message headers back from the server, each message header has a subject and a date/time and these get stored in the webdb using the phonegap webdb storage API.</p> <p>If I drop and recreate the message table and run the app fresh, the complete: function gets called once for each of the 18 messages I receive so 342 message headers gets displayed (18x18+18).</p> <p>No where in my code other than this one complete: does showAllHeaders(); get called.</p> <p>I placed an alert inside showAllHeaders() and that alert gets triggered 18 times.</p> <p>To narrow this down further I placed a loop counter inside my success: onFetchOK() like this:</p> <pre><code>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); </code></pre> <p>When this alert is called it shows "loopCount = 18" and this is called only once.</p> <p>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.</p> <p>So, it appears that my complete: function() is being called repeatedly... once as it should and then 18 more times.</p> <p>Anyone have any idea why this would be?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload