Hima
Hima

Reputation: 207

reloading the page in phonegap

I am updating the table values and then I want to display the updated table values in phonegap. For that I'm using the reload() method but when I am using this method the table is not updating (the code related to the database is not executing) but reloading is happening. Can anyone please help me how to display the updated values of table using reload or not using reload..? My code is

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();
         }

Upvotes: 5

Views: 4685

Answers (3)

taruna-systematix
taruna-systematix

Reputation: 111

You can use :-

window.location.reload(true);

Upvotes: 1

Lee-Ying Wu
Lee-Ying Wu

Reputation: 81

Try this

jQuery.mobile.changePage( nextPage); // nextPage is the page you would like to load

Upvotes: 0

Hima
Hima

Reputation: 207

It is working fine when i wrote location .reload() in function like this

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);

     }

Upvotes: 0

Related Questions