You can work with a conditional. Cordova has the connection plugin as below.
function checkConnection() {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
checkConnection();
Every time there is connectivity, send it to the server. If not, send it to locastorage
.
Then comes the synchronization. Do it this way (simplest way);
Save an update time field, and compare your server with the client and always check the latest.
Another way of doing:
http://coenraets.org/blog/2012/05/simple-offline-data-synchronization-for-mobile-web-and-phonegap-applications/
EDIT
I found this plugin: https://github.com/phonegap/phonegap-plugin-contentsync
Hmmm... ta giving a light. In case this check should be from time to time, at the time you press the save button or before opening the registration?
– Ezequiel Tavares
It may be from time to time, but depending on the number of requests it would overload the server. So beware
– Lucas Torres
this last plugin that you put me seemed to sync files, proceeds?
– Ezequiel Tavares
That, I never used it, but I suspect that if you pass a URL it will also work. If it doesn’t work, let me know that I edit the answer
– Lucas Torres