|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <title>jSQLEverywhere Example Client</title> |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 7 | + </head> |
| 8 | + <body> |
| 9 | + <center> |
| 10 | + <h2>Client example 2</h2> |
| 11 | + <p style="width:60%;">Any jSQL committed to the server will be visible on any page which connects to the same jSQLEverywhere server</p> |
| 12 | + <div id="ServerCount">Connecting to server</div> |
| 13 | + <p style="width:60%;">Once the server has connected you open the other example links and you will see that it was loaded on this list.</p> |
| 14 | + <a href="example1.html">Example 1</a><br> |
| 15 | + <a href="example3.html">Example 3</a> |
| 16 | + </center> |
| 17 | + |
| 18 | + <script src="../jSQLe.js"></script> |
| 19 | + <script> |
| 20 | + |
| 21 | + // Load jSQLEverywhere which will load jSQL Server |
| 22 | + jSQLe.load({ |
| 23 | + role: "client", |
| 24 | + server: "http://localhost/jSQL/plugins/jSQLEverywhere/server.html" |
| 25 | + }); |
| 26 | + |
| 27 | + // Once jSQL is loaded, we can use it |
| 28 | + jSQL.load(function(){ |
| 29 | + var FileName = window.location.pathname.split("/").pop(); |
| 30 | + var now = new Date(); |
| 31 | + |
| 32 | + // create a table on the serverif it does not exist |
| 33 | + jSQL.query("CREATE TABLE IF NOT EXISTS `ServerTest` (`FileName` VARCHAR, `Date` DATE)").execute(); |
| 34 | + |
| 35 | + // insert the current time and file name |
| 36 | + jSQL.query("INSERT INTO `ServerTest` VALUES (?, ?)").execute([FileName, now]); |
| 37 | + jSQL.commit(); |
| 38 | + |
| 39 | + drawTable(); |
| 40 | + }); |
| 41 | + |
| 42 | + function drawTable(){ |
| 43 | + var ServerCount = document.getElementById("ServerCount"); |
| 44 | + setInterval(function(){ |
| 45 | + jSQL.rollback(function(){ |
| 46 | + var data = jSQL.query("SELECT * FROM `ServerTest` ORDER BY `Date` DESC").execute().fetchAll("ASSOC"); |
| 47 | + var html = ["<table>"]; |
| 48 | + for(var i=0; i<data.length; i++) |
| 49 | + html.push("<tr><td>"+i+"</td><td>"+data[i].FileName+"</td><td>"+data[i].Date.getTime()+"</td></tr>"); |
| 50 | + ServerCount.innerHTML = html.join("")+"</table>"; |
| 51 | + }); |
| 52 | + },1500); |
| 53 | + } |
| 54 | + </script> |
| 55 | + </body> |
| 56 | +</html> |
0 commit comments