How to run a function when device comes to online state

I have created a app that uses sqlite db.I track the events that happened when offline.Then when the device comes to online.I want to update that events to mysql db in to do that??

so you need an endpoint for that on server side. So you can send an http-request with the data you want to store in the sql table.

This endpoint handles an array/list of your event-objects.

Server side is php and mysql.How to send http request when device comes to online state??

use the $http-service of angular.

How to trigger http-request when the device state changes to online

Like this:

document.addEventListener('online', function () {
  $, DATA).then(successFn, errorFn).finally($scope.$apply);

But keep in mind you need cordova-network-information plugin to react on online/offline events.

thanks :slight_smile: