Javascript: Can't add data to database if redirecting to another page later -


i'm having strange problem javascript can fill in form, , click save save data form database if add window.location.href = "deadlines.html" end of function insert db, redirect page, data not saved db

this code: http://jsfiddle.net/ajste/

<form id="formdeadlineinfo">         <label for="shortdescription">short description</label>         <input id="shortdescription"  type="text">         <br>         <label for="class">class</label>         <select id="class" class="ui-selectmenu" >           <option value="hci">hci</option>           <option value="datamining">data mining</option>           <option value="mobiledev">mobile dev</option>           <option value="ethics">ethics</option>         </select>         <br>         <label for="duedate">due date</label>         <input id="duedate" type="date">         <br>         <label for="duetime">due time</label>         <input id="duetime" type="time">         <br>         <label for="type">type</label>         <select id="type">           <option value="homework">homework</option>           <option value="test">test</option>         </select>         <br>         <label for="additionalinfo">additional info</label>         <input id="additionalinfo" type="text">         <br>         <label for="finished">finished</label>         <select data-role="flipswitch" id="finished" class="ui-selectmenu" >           <option value="no" selected>no</option>           <option value="yes">yes</option>          </select>          <input type="button" class="ui-btn ui-btn-active ui-btn-icon-bottom" data-role="button" value="save" style="text-align:center" onclick="getforminfo()">      </form> 

and javascript: http://jsfiddle.net/ajste/ sorry "code" function of hard handle, please see in jsfiddle

i opened , populated database before codes run don't need ask thank u if u can me solve problem

but if add window.location.href = "deadlines.html" end of function insert db, redirect page, data not saved db

it's not strange @ all. insert operation asynchronous, means code starts it, finishes later (which why accepts callback).

if tell code take user away page, asynchronous operation cancelled before completes. you'll need wait , use code writing window.location.href within success callback.

e.g.:

function insertdeadlinetodb(dbid,dbdescription,dbclass,dbduedate, dbduetime, dbtype, dbadditionalinfo, dbfinished) {     //alert('insert called');      //alert('before insert');     db.transaction(function(tx){         tx.executesql(             'insert deadlines (id, description, class, duedate, duetime, type, additionalinfo, finished) values (?,?,?,?,?,?,?,?)',             [dbid,dbdescription,dbclass,dbduedate, dbduetime, dbtype, dbadditionalinfo, dbfinished], function() {                successcb();                window.href.location = "deadlines.html"; // <=== here             }, errorcb);         ////alert(tx);    });    //window.href.location = "deadlines.html";              <=== not here } 

side note: code has missing variables, such successcb isn't defined anywhere.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -