In alert, it shows the data but not in the home screen

advertisements

I am using PhoneGap SQLite, and I am facing a problem that the data is not displaying. The alert(scripts) is showing that the data is there, but it is not showing on the home screen. Help me figure out what mistake I have done in code.

Thanks in advance.

In jQuery:

function get_Emp_List() {
           $("#employee").empty();

           $(location).attr('href', '#emp1');
           $.support.cors = true;
           $.ajax({
                type: "GET",
                url: "one.html",
                contentType: "text/xml",
                dataType: "xml",
                data: "",
            crossDomain:true,
                success: function (data) {
                          $(data).find("employee").each(function () {   

                          var emp_id = $(this).find('id').text();
                          var emp_name = $(this).find('short_name').text();

                           db.transaction(function(transaction) {
                                 transaction.executeSql('INSERT INTO Envy_Emp VALUES((SELECT max(_idEE)+1 FROM Envy_Emp),"'+emp_id+'","'+emp_name+'")',nullHandler,errorHandler);
                            });
                             });
                     ids_Dynamic_Emp_List();

                          return false;
                       },
                error: function (data) {
                        alert("error");
                }
            });
  }

      /*  end Employee list script */

   /*ids_Dynamic_Emp_List() method coding Start*/ 

  function ids_Dynamic_Emp_List(){
  /*sql start*/

  /*sqlite code for dynamic Emp list*/
  db.transaction(function(tx){
    tx.executeSql('SELECT * FROM Envy_Emp;', [], 

        function(tx,results){

                   if (results != null && results.rows != null) {
                    var myLen=results.rows.length;
                     for (var i = 0; i < results.rows.length; i++) {
                         var for_Name = results.rows.item(i).Envy_Emp_Name;
                         var for_ID = results.rows.item(i).Envy_Emp_ID;
                         var for_E_ID=results.rows.item(i)._idEE;
                        /*create table list Dynamically using Sqlitedata base */
                             var scripts = "<a href='#' data-role='button' data-theme='b' data-inline='true' onclick='get_Menu_List(id);' id='"+for_E_ID+"'>"+for_Name+"</a>";
                             alert(scripts);
                          $(".employee1")
                          .append(scripts)
                          .trigger('create');
                        /*create table list Dynamically using Sqlitedata base End*/
                        }
                      }
                   },errorHandler);
                  }
                 ,errorHandler,nullHandler);
                 return;
                  }

In HTML:

<div data-role="page" id="emp1">
  <div date-role="content">
    <div id="employee" class="employee1"/>
  </div>
</div>


Can you please try this.

In this function call a function and pass data, instead of appending the codes. In the called function, append passed data.

function ids_Dynamic_Emp_List(){
  /*sql start*/

  /*sqlite code for dynamic Emp list*/
  db.transaction(function(tx){
  tx.executeSql('SELECT * FROM Envy_Emp;', [], 

        function(tx,results){

                   if (results != null && results.rows != null) {
                    var myLen=results.rows.length;
                     for (var i = 0; i < results.rows.length; i++) {

                             appendScripts(results.rows.item(i)); /*call function*/

                        /*create table list Dynamically using Sqlitedata base End*/
                        }
                      }
        },errorHandler);
   },errorHandler,nullHandler);
   return;
}

Then append data here,

    /*function appends data to div*/
    function appendScripts(values){
          var for_Name = values.Envy_Emp_Name;
          var for_ID = values.Envy_Emp_ID;
          var for_E_ID= values._idEE;

          /*create table list Dynamically using Sqlitedata base */
          var scripts = "<a href='#' data-role='button' data-theme='b' data-inline='true' onclick='get_Menu_List(id);' id='"+for_E_ID+"'>"+for_Name+"</a>";
          $(".employee1").append(scripts).trigger('create');
    }

UPDATE Found issue with html 5, change html to,

<div data-role="page" id="emp1">
       <div date-role="content">
          <div id="employee" class="employee1"></div>
       </div>
 </div>