cordova - Using Jquery with PhoneGap -


i testing modified version of 1 of phonegap quick starts. referenced jquery. however, when want change content of div using jquery, got error, simple alert works fine.

function querysuccess(tx, results) { var s = ""; (var i=0; i<len; i++){ s += "row = " + + " id = " + results.rows.item(i).id + " data = " + results.rows.item(i).data + "<br />"; } //this cause error //$("#cnt").html(s); //this works fine alert(s); } 

could tell me missing? full code below.

<!doctype html> <html> <head> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" /> <meta charset="utf-8"> <!-- if application targeting ios before 4.0 must put json2.js http://www.json.org/json2.js www directory , include here --> <script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" /> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script> <script type="text/javascript" charset="utf-8"> // wait phonegap load // document.addeventlistener("deviceready", ondeviceready, false); // populate database // function populatedb(tx) { tx.executesql('drop table if exists demo'); tx.executesql('create table if not exists demo (id unique, data)'); tx.executesql('insert demo (id, data) values (1, "first row")'); tx.executesql('insert demo (id, data) values (2, "second row")'); } // query database // function querydb(tx) { tx.executesql('select * demo', [], querysuccess, errorcb); } // query success callback // function querysuccess(tx, results) { var len = results.rows.length; console.log("demo table: " + len + " rows found."); var s = ""; (var i=0; i<len; i++){ console.log("row = " + + " id = " + results.rows.item(i).id + " data = " + results.rows.item(i).data); s += "row = " + + " id = " + results.rows.item(i).id + " data = " + results.rows.item(i).data + "<br />"; } $("#cnt").html(s); //alert(s); } // transaction error callback // function errorcb(err) { console.log("error processing sql: "+err.code); } // transaction success callback // function successcb() { var db = window.opendatabase("database", "1.0", "phonegap demo", 200000); db.transaction(querydb, errorcb); } // phonegap ready // function ondeviceready() { var db = window.opendatabase("database", "1.0", "phonegap demo", 200000); db.transaction(populatedb, errorcb, successcb); } </script> </head> <body onload="onbodyload()"> <h1>example</h1> <p>open database</p> <div id="cnt">this</div> </body> </html> 

the code works fine in device in browser

http://jsfiddle.net/dhavaln/ujkuf/

as have mentioned cdn url jquery , jquery mobile, make sure libraries loaded code in using jquery.

$("#cnt").html(s); 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -