Saturday, 15 March 2014

HTML5 Offline storage not working -


This is the code provided by the W3C example for offline web storage:

  & Lt; ! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Script type = "text / javascript" charset = "UTF-8" & gt; Function render note (line) {console.log (line); } Function report error (source, message) {console.log ("mistake"); } Function renderNotes () {db.transaction (function (tx) {tx.executeSql ('if notes are not present (title text, body text)', []); tx.executeSQL ('SELECT * FROM Notes',' Select '[], function (tx, rs) {for (var i = 0; i & lt; rs.rows.length; i ++) {render notes (rs.rows [i]);}}); }); } Function insertNote (title, text) {db.transaction (function (tx) {tx.executeSQL ('(?,?)' In notes value, [title, text], function (tx, rs) {// ?? |}, Function (tx, error) {report error ('sql', error message);});}); } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

There is no console log-out output at all, what's the matter?

The function definition of DB and execution was missing.

OpenDatabase ("Notes", " Example Notes App! ", 1048576); Function render note (line) {console.log (line); } Function report error (source, message) {console.log ("mistake"); } Function renderNotes () {db.transaction (function (tx) {tx.executeSql ('if notes are not present (title text, body text)', []); tx.executeSQL ('SELECT * FROM Notes',' Select '[], function (tx, rs) {for (var i = 0; i & lt; rs.rows.length; i ++) {render notes (rs.rows [i]);}}); }); } Function insertNote (title, text) {db.transaction (function (tx) {tx.executeSQL ('(?,?)' In notes value, [title, text], function (tx, rs) {// ?? |}, Function (tx, error) {report error ('sql', error message);});}); } RenderNotes ();

Even more simple

  var db = openDatabase ("notes", "", "example notes app!" , 10000); Db.transaction (function (t) {//t.executeSql("DROP Table Notes "}; t.executeSql (" Make the Tables if Notes are not present (Title Text, Body Text) "); t.executeSql (" INSERT INTO notes value (?,?) ", ['Title', 'content']);});    

No comments:

Post a Comment