Dlaczego funkcja setOnline(false); nie chce się wykonać?
window.onbeforeunload = function() { setOnline(false); }
function setOnline(instance) { if(instance == true) { var jqxhrT = $.post("service.php?action=setTrue"); } else if(instance == false) { var jqxhrF = $.post("service.php?action=setFalse"); } }
function setOnline(instance) { if(instance == true) { var jqxhrT = $.post("service.php?action=setTrue"); alert('xx'); } else if(instance == false) { var jqxhrF = $.post("service.php?action=setFalse", function() { alert( "success" ); }) .done(function() { alert( "second success" ); }) .fail(function() { alert( "error" ); }) .always(function() { alert( "finished" ); }); } } window.onbeforeunload = function() { setOnline(false); }
var instance; $(document).ready(function() { setOnline("yes"); checkMode(); }); function setOnline(mode) { if(mode == "yes") { instance == true; } if(mode == "no") { instance == false; } } function checkMode() { if(instance == true) { var jqxhrT = $.post("service.php?action=setTrue"); alert('xx'); } else if(instance == false) { var jqxhrF = $.post("service.php?action=setFalse", function() { alert( "success" ); }) .done(function() { alert( "second success" ); }) .fail(function() { alert( "error" ); }) .always(function() { alert( "finished" ); }); } } window.onbeforeunload = function() { setOnline("false"); checkMode(); }
<?php include 'online.php'; @$akcja = $_GET["action"]; { $nowy = new Baza(); $data = $nowy->getData(); } { $nowy = new Baza(); $nowy->setRow("online"); } { $nowy = new Baza(); $nowy->setRow("offline"); } ?>
<?php Class Baza { public function __construct() { $this->Connect(); } public function Connect() { try { $pdo = new PDO('mysql:host=localhost;port=3306;dbname=test', '', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'")); $pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if($pdo) { $this->conn = $pdo; return true; } } catch(PDOException $e) { } } public function setRow($text) { if($this->conn) { $dodaj = $this->conn->prepare("UPDATE `is_online` SET `online`=:online"); $dodaj-> bindValue(":online", $text, PDO::PARAM_STR); $dodaj->execute(); $dodaj->closeCursor(); } } public function getData() { if($this->conn) { $_check = $this->conn->prepare("SELECT `online` FROM `is_online`"); $_check-> execute(); if($dane = $_check -> fetch()) { } } } }