无法调用null的方法'transaction'

时间:2013-01-28 14:41:14

标签: javascript html5 local-storage web-sql

我收到以下错误

无法调用null

的方法'transaction'

尝试插入WEBSQL时(是的,我知道它已被弃用)。

我有一个几乎完全相同的这个脚本在另一个页面上正常工作,这个只有一个不同的名称和单独的字段。代码如下。

var html5rocks = {};
html5rocks.webdb = {};

html5rocks.webdb.db = null;

html5rocks.webdb.open = function() {
    var dbSize = 5 * 1024 * 1024; // 5MB
    html5rocks.webdb.db = openDatabase('Customer', '1.0', 'customer manager', dbSize);
}

html5rocks.webdb.onError = function(tx, e) {
    alert('Something unexpected happened: ' + e.message );
    console.log('error');
}

html5rocks.webdb.onSuccess = function(tx, r) {


    var statusOutput = "Customer Form Saved!";
    var status = document.getElementById('status');
    $('.form-title-area').css('background-color','#26c622');
    $('.form-title-area').html('<h1>Customer Form Saved!</h1>');
    status.innerHTML = statusOutput;

    html5rocks.webdb.getAllTodoItems(loadTodoItems);
}

html5rocks.webdb.createTable = function() {
    html5rocks.webdb.db.transaction(function(tx) {
                                    tx.executeSql('CREATE TABLE IF NOT EXISTS ' + 
                                                  'customerform(ID INTEGER PRIMARY KEY ASC, companyname TEXT, tradingas TEXT, regadd1 TEXT, regadd2 TEXT, regaddcity TEXT, regaddstate TEXT, regaddcountry TEXT, regaddpostcode TEXT, cregno TEXT, vatregno TEXT, accountsname TEXT,  accountsphone TEXT, accountsemail TEXT, accountsfax TEXT, invadd1 TEXT, invadd2 TEXT, invaddcity TEXT, invaddstate TEXT, invaddcountry TEXT, invaddpostcode TEXT, creditlimit TEXT, firstorder TEXT, reqdeldate TEXT, deladd1 TEXT, deladd2 TEXT, deladdcity TEXT, deladdstate TEXT, deladdcountry TEXT, deladdpostcode TEXT, buyingname TEXT, buyingphone TEXT, buyingemail TEXT, buyingfax TEXT, ordersource TEXT, currency TEXT, deliveryterms TEXT, maxpallet TEXT, pallettype TEXT, wrap TEXT, invoiceterms TEXT, specialinstructions TEXT, bookingname TEXT, bookingphone TEXT, signed TEXT, signeddate TEXT, inputby TEXT, inputdate TEXT, added_on DATETIME)', []);
                                    });


}

html5rocks.webdb.addTodo = function(companynameText, tradingasText, regadd1Text, regadd2Text, regaddcityText, regaddstateText, regaddcountryText, regaddpostcodeText, cregnoText, vatregnoText, accountsnameText, accountsphoneText, accountsemailText, accountsfaxText, invadd1Text, invadd2Text, invaddcityText, invaddstateText, invaddcountryText, invaddpostcodeText, creditlimitText, firstorderText, reqdeldateText, deladd1Text, deladd2Text, deladdcityText, deladdstateText, deladdcountryText, deladdpostcodeText, buyingnameText, buyingphoneText, buyingemailText, buyingfaxText, ordersourceText, currencyText, deliverytermsText, maxpalletText, wrapText, invoicetermsText, specialinstructionsText, bookingnameText, bookingphoneText, signedText, signeddateText, inputbyText, inputdatetext) {


    html5rocks.webdb.db.transaction(function(tx){


                                    var addedOn = new Date();
                                    tx.executeSql('INSERT INTO customerform(companyname, tradingas, regadd1, regadd2, regaddcity, regaddstate, regaddcountry, regaddpostcode, cregno, vatregno, accountsname, accountsphone , accountsemail, accountsfax, invadd1, invadd2, invaddcity, invaddstate, invaddcountry, invaddpostcode, creditlimit, firstorder, reqdeldate, deladd1, deladd2, deladdcity, deladdstate, deladdcountry, deladdpostcode, buyingname, buyingphone ,buyingemail, buyingfax, ordersource, currency, deliveryterms, maxpallet, pallettype, wrap, invoiceterms, specialinstructions, bookingname, bookingphone, signed, signeddate, inputby, inputdate, added_on) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', 
                                                  [companynameText, tradingasText, regadd1Text, regadd2Text, regaddcityText, regaddstateText, regaddcountryText, regaddpostcodeText, cregnoText, vatregnoText, accountsnameText, accountsphoneText, accountsemailText, accountsfaxText, invadd1Text, invadd2Text, invaddcityText, invaddstateText, invaddcountryText, invaddpostcodeText, creditlimitText, firstorderText, reqdeldateText, deladd1Text, deladd2Text, deladdcityText, deladdstateText, deladdcountryText, deladdpostcodeText, buyingnameText, buyingphoneText, buyingemailText, buyingfaxText, ordersourceText, currencyText, deliverytermsText, maxpalletText, pallettypeText, wrapText, invoicetermsText, specialinstructionsText, bookingnameText, bookingphoneText, signedText, signeddateText, inputbyText, inputdateText, addedOn],
                                                  html5rocks.webdb.onSuccess,
                                                  html5rocks.webdb.onError);
                                    });


}




function init() {
    html5rocks.webdb.open();
    html5rocks.webdb.createTable();
    html5rocks.webdb.getAllTodoItems(loadTodoItems);

}

function initi() {

    html5rocks.webdb.getRecords();
}

function addTodo() {
console.log('trigger');
    var companyname = document.getElementById('companyname');
    var tradingas = document.getElementById('tradingas');
    var regadd1 = document.getElementById('regadd1');
    var regadd2 = document.getElementById('regadd2');
    var regaddcity = document.getElementById('regaddcity');
    var regaddstate = document.getElementById('regaddstate');
    var regaddcountry = document.getElementById('regaddcountry');
    var regaddpostcode = document.getElementById('regaddpostcode');
    var cregno = document.getElementById('cregno');
    var vatregno = document.getElementById('vatregno');
    //var vatregno = $('vatregno').val();
    var accountsname = document.getElementById('accountsname');
    var accountsphone = document.getElementById('accountsphone');
    var accountsemail = document.getElementById('accountsemail');
    var accountsfax = document.getElementById('accountsfax');
    var invadd1 = document.getElementById('invadd1');
    var invadd2 = document.getElementById('invadd2');
    var invaddcity = document.getElementById('invaddcity');
    var invaddstate = document.getElementById('invaddstate');
    var invaddcountry = document.getElementById('invaddcountry');
    var invaddpostcode = document.getElementById('invaddpostcode');
    var creditlimit = document.getElementById('creditlimit');
    var firstorder = document.getElementById('firstorder');
    var reqdeldate = $('.reqdeldate');
    var deladd1 = document.getElementById('deladd1');
    var deladd2 = document.getElementById('deladd2');
    var deladdcity = document.getElementById('deladdcity');
    var deladdstate = document.getElementById('deladdstate');
    var deladdcountry = document.getElementById('deladdcountry');
    var deladdpostcode = document.getElementById('deladdpostcode');
    var buyingname = document.getElementById('buyingname');
    var buyingphone = document.getElementById('buyingphone');
    var buyingemail = document.getElementById('buyingemail');
    var buyingfax = document.getElementById('buyingfax');
    var ordersource = document.getElementById('ordersource');
    var currency = document.getElementById('currency');
    var deliveryterms = document.getElementById('deliveryterms');
    var maxpallet = document.getElementById('maxpallet');
    var pallettype = document.getElementById('pallettype');
    var wrap = document.getElementById('wrap');
    var invoiceterms = document.getElementById('invoiceterms');
    var specialinstructions = document.getElementById('specialinstructions');
    var bookingname = document.getElementById('bookingname');
    var bookingphone = document.getElementById('bookingphone');
    var signed = document.getElementById('signed');
    var signeddate = $('.signeddate');
    var inputby = document.getElementById('inputby');

    var inputdate = $('.inputdate');

    console.log('triggers2');



    html5rocks.webdb.addTodo(companyname.value, tradingas.value, regadd1.value, regadd2.value, regaddcity.value, regaddstate.value, regaddcountry.value, regaddpostcode.value, cregno.value, vatregno.value, accountsname.value, accountsphone.value, accountsemail.value, accountsfax.value, invadd1.value, invadd2.value, invaddcity.value, invaddstate.value, invaddcountry.value, invaddpostcode.value, creditlimit.value, firstorder.value, reqdeldate.value, deladd1.value, deladd2.value, deladdcity.value, deladdstate.value, deladdcountry.value, deladdpostcode.value, buyingname.value, buyingphone.value, buyingemail.value, buyingfax.value, ordersource.value, currency.value, deliveryterms.value, maxpallet.value, pallettype.value, wrap.value, invoiceterms.value, specialinstructions.value, bookingname.value, bookingphone.value, signed.value, signeddate.value, inputby.value, inputdate.value);

    alert('Customer Form Saved');

}

有没有人知道这个问题究竟是什么?我很难过

0 个答案:

没有答案