Project

General

Profile

InitializeSubscriber JavaScript » History » Version 1

Tomek Dziemidowicz, 2019-07-04 09:02 PM

1 1 Tomek Dziemidowicz
h1. InitializeSubscriber JavaScript
2
3
<pre><code class="javascript">
4
$.ajax({
5
    url: sqlitesync_SyncServerURL + "InitializeSubscriber/" + sqlitesync_syncPdaIdent,
6
    method: 'GET',
7
    scope: this,
8
    cache: false,
9
    timeout: 10 * 60 * 1000, //4min
10
    success: function (response, status) { //Success Callback
11
        var responseReturn = JSON.parse(response);
12
13
        sqlitesync_AddLog('<p>Connected to server...</p>');
14
        sqlitesync_DB.transaction(function (tx) {
15
16
            Object.keys(responseReturn)
17
                  .sort()
18
                  .forEach(function(v, i) {
19
                        tx.executeSql(responseReturn[v],
20
                            null,
21
                            function (transaction, result) {
22
                                sqlitesync_AddLog('Creating object <b>' + v + '</b>...');
23
                            },
24
                            function (transaction, error) {
25
                                console.log('Object ' + v  + '; ' + error.message + ' (Code ' + error.code + ')');
26
                            });
27
                   });
28
29
        }, function (error) {//error
30
            sqlitesync_AddLog('<p>Error while syncing with the server ' + error + '</p>');
31
        }, function () {
32
            sqlitesync_AddLog('<p style=\"font-weight:bold; color:green;\">Synchronization completed</p>');
33
        });
34
35
    },
36
    failure: function (result, request) {
37
        var statusCode = result.status;
38
        var responseText = result.responseText;
39
        sqlitesync_AddLog('<p>Error while syncing with the server ' + responseText + '</p>');
40
    }
41
});
42
</code></pre>
Go to top