Transaction doesn't always execute

14 views Asked by At

I have a script that builds html, but it's not always executed, when I refresh the page enough it finally does what it needs to, what am I doing wrong?

Funny enough I have collegues who execute the page on a tablet and there the issue doesn't exist.

    function queryAndUpdateOverview(){

    var query = "SELECT * FROM transportplanning where dlvModeIDMain = '" + route + "' order bysequenceNumber";
      console.log(query);

    try {
       localDB.transaction(function(transaction){

          console.log('executeSQL');

          transaction.executeSql(query, [], function(transaction, results){

          console.log('number of records: ' + results.rows.length);

            tbody = document.getElementById('dataTable').getElementsByTagName('tbody')[0];
    
            for (var i = 0; i < results.rows.length; i++) {

                var row = results.rows.item(i);

                console.log('SequenceNumber: ' + sequenceNumber);

                  tr = document.createElement('TR');

                  td = document.createElement('TD');                                       
                  tdText = document.createTextNode('');
                  td.appendChild(tdText);
                  tr.appendChild(td);

                  td = document.createElement('TD');       
                  td.setAttribute('class', 'tdCenter');
                  span = document.createElement('span');                          
                  spanInnerHTML = sequenceNumber;
                  span.innerHTML = spanInnerHTML;
                  td.appendChild(span);                                        
                  tr.appendChild(td);
          
                  tr.appendChild(td);                                             

                  tbody.appendChild(tr);                    
        
              }
      
            }, function(transaction, error){
                console.log('Error: ' + error.code + '<br>Message: ' + error.message);
            });
          });
        } 
        catch (e) {
            console.log('Error: Unable to select data from the db ' + e + '.');
        }
    }
0

There are 0 answers