Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * this code is based on Raymond Camdens blog post:
- * Adding database synchronization to your PhoneGap project
- * http://bit.ly/14tXNm4
- * requires the json2.js library (parser)
- */
- function uploadFromDevice() {
- var newRows = new Array();
- var date = localStorage["lastdate"]?localStorage["lastdate"]:'';
- if (date == '') date = '2000-01-01 12:00:00'; // really long ago
- console.log('checking if there are any rows modifed/inserted after '+ date);
- db.transaction(function(ctx) {
- ctx.executeSql("select name,description,LastModDate,deleted,token " +
- "from docs where LastModDate > ?", [date], function(tx,checkres) {
- if(checkres.rows.length) {
- console.log('found ' + checkres.rows.length + ' rows that need to be uploaded to the server!');
- for(var i=0; i<checkres.rows.length; i++) {
- uRows.push(checkres.rows.item(i));
- }
- json = JSON.stringify(uRows);
- $.get(uploadUrl, {rows:json}, function(response, code){
- console.log(response);
- });
- }
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement