我正在更新表值,然后我想在phonegap中显示更新的表值.为此,我正在使用reload()方法,但是当我使用此方法时,表没有更新(与数据库相关的代码没有执行),但正在重新加载. 任何人都可以帮我
任何人都可以帮我如何使用重新加载或不使用重新加载来显示表的更新值..?我的代码是
function save() { var v=0; //alert("save button"); // alert("global :"+global.length); for(var n=0;n<(global.length+l);n++) { //alert("hi"); var x1=$('input.current')[n]; //alert($(x1).val()); if($(x1).val()=="0") { // alert("compare"); var y1=$('input.new')[n]; newaloc[v]=$(y1).val(); //alert(newaloc[v]); v++; } } //var polno=init(); var db = window.openDatabase("DataBase", "3.6.22", "test", 200000); db.transaction(function(transaction) { transaction.executeSql('SELECT * FROM POLICIES_DET WHERE POLICY_NUMBER="'+polno+'";',[], function(transaction, result) { if (result != null && result.rows != null) { // alert(result.rows.length); for (var i = 0; i < result.rows.length; i++) { var row = result.rows.item(i); // $("#table").append("<tr><td class='fund'>"+row.FUND_DESC+"</td><td><input type='text' class='current' value='"+row.ALLOC_PERCNT+"' size='5' /></td><td><input type='text' class='new' value='"+row.FUND_VALUE+"' size='5' /></td><td><input type='text'class='new' size='5' /></td></tr>"); fund=row.INSURED_AMOUNT; //alert(fund); } } },errorHandler); },errorHandler,nullHandler); db.transaction(insert, errorCB, successCB); al//ert("after insert"); //alert("no of records:"+global.length); for(var i=0;i<global.length;i++) { var it=$('input.new')[i]; var k=$(it).val(); //if(k.length>0) //{ // alert("new allocation loop"); xx.push(k); //alert(xx[v]); v++; // } } v=0; db.transaction(function(transaction) { // alert("updation"); for(var j=0;j<xx.length;j++) { var c=xx[j]; //alert(c); var g=global[j]; //alert(g); if(c.length>0) { var vl=fund*(c/100); //alert(vl); transaction.executeSql('UPDATE FUND_DET SET ALLOC_PERCNT="'+c+'",FUND_VALUE="'+vl+'"WHERE POLICY_NUMBER="'+polno+'"AND FUND_DESC="'+g+'";',[], function(transaction, result) { if (result != null && result.rows != null) { //alert("Test other way"); for (var i = 0; i < result.rows.length; i++) { var row = result.rows.item(i); } } },errorHandler); }} },errorHandler,nullHandler); location.reload(); }当我在函数中写入位置.reload()时它工作正常
像这样
db.transaction(function(transaction) { // alert("updation"); for(var j=0;j<xx.length;j++) { var c=xx[j]; //alert(c); var g=global[j]; //alert(g); if(c.length>0) { var vl=fund*(c/100); //alert(vl); transaction.executeSql('UPDATE FUND_DET SET ALLOC_PERCNT="'+c+'",FUND_VALUE="'+vl+'"WHERE POLICY_NUMBER="'+polno+'"AND FUND_DESC="'+g+'";',[], function(transaction, result) { if (result != null && result.rows != null) { //alert("Test other way"); for (var i = 0; i < result.rows.length; i++) { var row = result.rows.item(i); } } location.reload(); },errorHandler); }} },errorHandler,nullHandler); }