Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ws = null, ws_ready = 0;
- $(function(){
- if ( wsc() ) {
- alert("Wrong Browser!");
- return -1;
- }
- });
- function login(){
- $.post("./cmd.php",
- $("#f_login").serializeArray(),
- function(data){
- if (data != "ok") {
- alert("login failed..");
- } else {
- window.location.href="./";
- }
- }
- );
- return false;
- }
- function join(){
- $.post("./cmd.php",
- $("#f_join").serializeArray(),
- function(data){
- if (data != "ok") {
- alert("join failed..");
- } else {
- alert("join success");
- window.location.href="./";
- }
- }
- );
- return false;
- }
- function transfer(){
- var data = {
- cmd : "transfer",
- id : $('#iid').val(),
- an : $('#an').val(),
- am : $('#am').val(),
- sk : $('#sk').val()
- };
- wss(data);
- return false;
- }
- function logout(){
- $.post("./cmd.php",
- {cmd : "logout"},
- function(data){
- window.location.href="./";
- }
- );
- }
- function wss(obj_data){
- if (ws_ready == 0) {
- setTimeout(function(){wss(obj_data);},500);
- return;
- }
- ret = ws.send(JSON.stringify(obj_data));
- //return ret;
- }
- function wsc(){
- if ("WebSocket" in window)
- return false;
- return true;
- }
- function global_sw(data){
- if (data == false){
- console.log("wrong connection");
- return -1;
- }
- result = JSON.parse(data);
- switch(result['c']){
- case "transfer" : {
- if (result['m']!="ok") {
- alert(result['m']);
- }
- }break;
- case "list" : {
- listup(result['m']);
- }break;
- default : console.log("unknown error");
- }
- }
- function list_init(){
- handleLoad();
- listing("balance", "desc");
- }
- function list_sw(sw){
- if (sw==1) { oo = "user"; }
- else { oo = "balance"; }
- if (bb=="asc") {bb = "desc";}
- else {bb = "asc";}
- listing(oo, bb);
- }
- function listing(c, d){
- oo = c; bb = d;
- wss({cmd:"list_init", o:c, b:d});
- }
- function listup(data){
- list = JSON.parse(data);
- tbl = "<table width='100%' id='listtbl'>";
- tbl += "<thead><tr><td><a href='#' onclick='list_sw(1);'>USER</a></td>";
- tbl += "<td><a href='#' onclick='list_sw(2);'>BALANCE</a></td></tr></thead>";
- $.each(list, function(idx, data){
- tbl += "<tr><td>"+data['user']+"</td><td>"+data['balance']+"</td></tr>";
- });
- tbl += "</table>";
- $('.pageContent').html(tbl);
- }
- function transfer_init(){
- handleLoad();
- }
- function handleUnload(){
- ws.close();
- }
- function handleLoad(){
- //ws = new WebSocket("ws://1.234.27.139:38089/banking");
- //ws = new WebSocket("ws://1.234.27.139:38090/banking");
- ws = new WebSocket("ws://1.234.27.139:40022/banking");
- ws.onopen = function(){
- console.log("opened.");
- ws_ready = 1;
- }
- ws.onclose = function(){
- console.log("closed.");
- }
- ws.onmessage = function(evt){
- global_sw(evt.data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement