Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Odliczanie, odliczanie conf.std
marcolo
post 5.10.2017, 08:31:42
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 5.10.2017

Ostrzeżenie: (0%)
-----


Potrzebne mi odliczanie od 4 godzin w dół, tak aby na serwerze odliczał się czas, a gdy użytkownik otwiera stronę, to pobiera mu się aktualny czas z serwera i za pomocą js-a zmniejsza do 0 i zaczyna od nowa.
Go to the top of the page
+Quote Post
Pyton_000
post 5.10.2017, 08:50:48
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Ok, specyfikację już znamy. To teraz jaki masz problem?
Go to the top of the page
+Quote Post
Neutral
post 5.10.2017, 11:14:49
Post #3





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

Ostrzeżenie: (0%)
-----


rast.php:
  1. <button id="ajaxButton" type="button">Make a request</button>
  2. <div id="split3"></div>
  3. <div id="split2"></div>
  4. <div id="split"></div>


Kod
(function(){
    var httpRequest;
    document.getElementById("ajaxButton").addEventListener("click",makeRequest);
    
    function makeRequest() {
        document.getElementById("ajaxButton").disabled = 'disabled';
        ////////////////////////////
        
        ////////////////////////////
        
        httpRequest = new XMLHttpRequest();
        
        if(!httpRequest){
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        httpRequest.onreadystatechange = alertContents;
        httpRequest.open('POST','rast2.php?timer=20');
        httpRequest.send();
    }
    
    function alertContents(){
        if(httpRequest.readyState === XMLHttpRequest.DONE){
            if (httpRequest.status === 200) {
                var responsese = (httpRequest.responseText);
                var respons1 = document.getElementById('split');
                var respons2 = document.getElementById('split2');
                var respons3 = document.getElementById('split3');
                var dL = responsese.split(':');
                
                var count = 0;
                function count_down() {
                    if(count == 4){
                        null;//stop
                    }else {
                        respons3.innerHTML = dL[0];
                        var tozero = respons1.innerHTML = dL[2]--;
                        respons2.innerHTML = dL[1];
                        if(tozero == 0) {
                            dL[2]=59;
                            respons2.innerHTML = dL[1]--;
                        }
                        if(dL[1]==0) {
                            dL[1]=59;
                            dL[0]--;
                            count++;
                            console.log(count);
                        }
                    }
                }
                    
                setInterval(count_down,1000);
                
            }else{
                alert('There was a problem with the request.');
            }
        }
    }
    
})();

rast2.php:
  1. <?php
  2. $x = new DateTime();
  3. echo $_POST['timer']= $x->format('H:i:s');
  4. ?>


Ten post edytował Neutral 5.10.2017, 11:16:40
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 31.07.2025 - 07:48