0

My code is below, the button works once but then doesnt change the following times i click it, this isnt the exact layout of my document but i think its the only relevant parts, any changes or better ways to do this are welcome, but im trying to avoid refreshing the page as ive got other items which take time to load

<button class="btn btn-primary btn-lg" onmouseup="change();" type="button" value="Ping                            Now" id="myButton1"> Ping Now </button>

<script>
function change()
    {
        <?php

            $starttime = microtime(true);
            $file      = fsockopen ($serverAddress, 80, $errno,   $errstr, 10);
            $stoptime  = microtime(true);
            $status    = 0;

            if (!$file) $status = -1;  // Site is down
            else {
                fclose($file);
                $status = ($stoptime - $starttime) * 1000;
                //$status = floor($status);
            }
            $timeTaken = round($status, 3);
        ?>

    document.getElementById("testButton").innerText = <?php echo json_encode($timeTaken); ?> ;
    }
</script>
Tcoombes
  • 1
  • 2
  • What is your question? – Cameron Tinker May 12 '14 at 17:55
  • 1
    Every time you want the server to do some work (like, process some php) you HAVE to send it a HTTP request. Either reload the page or use AJAX to do so. – James May 12 '14 at 17:56
  • sorry im a total noob really when it comes to javascript......is there any way you can show me how to set this up in AJAX? i sort of understand but cant get it working – Tcoombes May 12 '14 at 18:32

0 Answers0