0

I am using websql database to store my records successfully and while reading it back it returns undefined at first time on second time it returns actual value.

myDB.transaction(function(transaction) {
  transaction.executeSql('SELECT * FROM tempTelemedicine', [], function(transaction, output) {
    if (output != null && output.rows != null) {
      for (var i = 0; i < output.rows.length; i++) {
        var record = output.rows.item(i);
        this.date = record.date;
        this.firstName = record.firstName;
        this.lastName = record.lastName;
        this.address = record.address;
        this.clinic = record.clinic;
        this.mobile_no = record.mobile_no;
        this.age = record.age;
        this.age_afa = record.age_afa;
        this.number_oa = record.number_oa;
        this.number_oailsm = record.number_oailsm;
        this.months_sla = record.months_sla;
        this.sex = record.sex;
        this.predisposing = record.predisposing;
        this.color = record.color;
        this.stiff = record.stiff;
        this.shaking = record.shaking;
        this.tongue = record.tongue;
        this.incontinent = record.incontinent;
        this.head = record.head;
        this.eyes = record.eyes;
        this.communicates = record.communicates;
        this.weakness = record.weakness;
        this.comment = record.comment;
        alert("DATA SET");
        $('#lbUsers').append('<br>'+"new data"+'   '+ record.patientId
         + ' ' + record.date + ' ' + record.firstName + ' ' + record.lastName
         + ' ' + record.address + ' ' + record.clinic + ' ' + record.mobile_no
         + ' ' + record.age + ' ' + record.age_afa + ' ' + record.number_oa
         + ' ' + record.number_oailsm + ' ' + record.months_sla + ' '
         + record.sex + ' ' + record.predisposing + ' ' + record.color
         + ' ' + record.stiff + ' ' + record.shaking + ' ' + record.tongue
         + ' ' + record.incontinent + ' ' + record.head + ' ' + record.eyes
         + ' ' + record.communicates + ' ' + record.weakness + ' ' + record.comment);
      }
    }
  });
}

1 Answer 1

3

It is because of the Asynchronous mode of execution of JavaScript.
The web browser and JavaScript share a single thread for rendering and processing the code, in this case variable are used before they are assigned values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.