开发者

Problem with jQuery openDatabase(): variable db is undefined

开发者 https://www.devze.com 2023-01-29 16:16 出处:网络
I created a iPhone Web App with jQuery & jQTouch, that makes use of the local SQLite database of the Mobile Safari browser in the iPhone.

I created a iPhone Web App with jQuery & jQTouch, that makes use of the local SQLite database of the Mobile Safari browser in the iPhone.

The app was running great, up until a few days ago. Suddenly I get the following error message when trying to initialize the database:

TypeError: Result of expression 'db' [undefined] is not an object.

This error occurs while trying to execute the following code:

function openDB() {     
    db = openDatabase(dbName, '1.0', dbName);       
    db.transaction(  
        function(tx) {  
            tx.executeSql(  
                'CREATE TABLE IF NOT EXISTS energy_days ' +  
                '  ... (omitted) ... ;',  
             开发者_JAVA技巧   [],  
                nullDataHandler,  
                function(tx, error){        
                    alert('Error (CREATE TABLE): '+error.message+' (Code '+error.code+')');  
                    return true;  
                }  
            );  
        },   
        transactionErrorHandler,  
        nullDataHandler  
    );              
}

Of course, the variable db is defined globally.

Now, this code segment was working. Maybe this has something to do with the latest iOS 4.2 update? With this update, the whole database behaviour got kinda strange (e.g. they are not visible in the Settings anymore, until you restart the whole device).

Has anyone an idea how to fix this? Is there an alternate way to initialize a database object or am I missing something obvious?

Thanks for all replies, they are sincerely appreciated! Roland


I think I found the problem with the code above. As mentioned, it worked right until the upgrade to iOS 4 (and still does in Safari). Now it seems that the JS syntax of the most current Safari Mobile has been tightened.

Using the full blown code snipped from Apple's documentation (including short and display name, size etc.) it once again works in Mobile Safari.

Cheers!
Roland

0

精彩评论

暂无评论...
验证码 换一张
取 消