1

ここに私のスクリプト全体があります:

    document.addEventListener("deviceready", onDeviceReady, false); //add event for phonegap

    function resync(){

    var serviceURL = document.forms["form1"]["ServiceURL"].value;

    html5sql.process(
         [
             "DELETE FROM employees"
         ],
         function(){
          alert("loading xml");
             loadXML(serviceURL);
         },
         function(error, statement){
             alert("Error: " + error.message + " when processing " + statement);
         }        
     );
    }

    function onDeviceReady() {

    html5sql.openDatabase("emp", "HTML5 Web SQL Database", 6*300000*300000);
    html5sql.process("CREATE TABLE IF NOT EXISTS employees (empid , firstName, lastName, dob, title, department, officePhone, cellPhone, email, spousename, spousedob, marriageanniversary, picture, PRIMARY KEY (`empid`));")
    html5sql.process("CREATE TABLE IF NOT EXISTS config (ServiceURL);")

    $(document).ready(function()
    {
      renderEmployeeList();
    });


    function renderEmployeeList(){

      html5sql.process( 
        [
          {
            "sql": "SELECT * FROM config",
            "success": function(tx, results) {
              var len=results.rows.length;
              if (len==null || len==""){//check if config(serviceURL) is empty. If it is, go to settings.
                alert("XML Path is missing. Please enter a path in the settings.");
                window.location = '#settings';
              }else{
                  html5sql.process(//if config exists, start rendering employees.
                    [
                      {
                        "sql": "SELECT * FROM employees",
                        "success": function(tx, results) {
                          alert("called output select");
                          var len=results.rows.length;
                          var i;
                          for(i=0; i<len; i++) {
                            $("#output").append('<a data-ajax="false" href="employeedetails.html?id=' + results.rows.item(i).empid + '"><li class="ui-btn ui-btn-up-c ui-btn-icon-right ui-li-has-arrow ui-li" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-icon="arrow-r" data-iconpos="right" data-theme="c"><div id="outputdiv" class="ui-content" style="cursor: pointer;">' + results.rows.item(i).firstName + ' ' + results.rows.item(i).lastName + '</div></li></a>');
                          }
                        }
                      }
                    ]
                  );
              }
            }
          }
        ]
      );

    }
    }

    function loadXML(XMLurl){
      alert (XMLurl);
      $.ajax({
          type: "GET",
          url: XMLurl,
          dataType: "xml",
          success: parseXml
        });  
    }

    function parseXml(xml)
    {

      $(xml).find("employee").each(function()
        {
          alert("each called");
          var $this = $(this),
          $empid = $this.attr("empid"),
          $firstName = $this.attr("firstName"),
          $lastName = $this.attr("lastName"),
          $dob = $this.attr("dob"),
          $title = $this.attr("title"),
          $department = $this.attr("department"),
          $officePhone = $this.attr("officePhone"),
          $cellPhone = $this.attr("cellPhone"),
          $email = $this.attr("email"),
          $spousename = $this.attr("spousename"),
          $spousedob = $this.attr("spousedob"),
          $marriageanniversary = $this.attr("marriageanniversary"),
          $picture = $this.attr("picture");

          alert("FName " + $firstName);

          html5sql.process(
            [
              {
                "sql": "INSERT INTO employees (empid , firstName, lastName, dob, title, department, officePhone, cellPhone, email, spousename, spousedob, marriageanniversary, picture) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                "data": [$empid, $firstName, $lastName, $dob, $title, $department, $officePhone, $cellPhone, $email, $spousename, $spousedob, $marriageanniversary, $picture],
              }
           ]
          );
        }
      )
    }




    /* Save Configuration */
    function saveconfig(){

      var serviceURL = document.forms["form1"]["ServiceURL"].value;

      html5sql.process(
        [
          {
            "sql": "DROP TABLE config"
          }
        ]
      );

      html5sql.process(
        [
          {
            "sql": "CREATE TABLE IF NOT EXISTS config (ServiceURL)"
          }
        ]
      );

      html5sql.process(
        [
          {
            "sql": "INSERT INTO config (ServiceURL) VALUES (?)",
            "data": [serviceURL],
            "success": function(){
            alert("URL Saved.");
            loadXML(serviceURL);
            }
          }
        ]
      );

    }

html5sql.com の html5sql.js を使用しました

関数 resync() はエラーを出さず、実際には正しい ServiceURL で loadXML を呼び出します。ただし、リモート xml の変更はここには反映されません。私は何日もこれにこだわっています。あらゆる種類の助けをいただければ幸いです。ありがとう。

4

0 に答える 0