javascript - AJAX Inconsistant Return Value -



javascript - AJAX Inconsistant Return Value -

i have simple ajax phone call php script on server usb temperature probe inserted. when temperature on 100, ajax phone call doesn't consistently homecoming proper temperature. returns finish temperature (i.e. 145.78), returns on 100 part (i.e. 45.78).

running php script command line produces consistent result every time; regardless of how many times in row run it.

i created php file , had echo out 123.45 , ran through ajax call, , seemed homecoming finish number consistently.

here sample code pertaining this:

js

function monitorloop() { $.ajax({ url: 'temp0.php', type: 'get', datatype: 'html', success: function(data) { console.log( info ); } }); } $("#togglemonitor").on( "click", function() { looping = !looping; if (looping) { loop = setinterval( function() { monitorloop(); }, 1000 ); } else { clearinterval( loop ); } });

php

<?php $pattern = '/[0-9]*[0-9][0-9]\.[0-9][0-9]/'; $temperature = exec('sudo pcsensor -f -n0'); preg_match( $pattern, $temperature, $output, preg_offset_capture); echo $output[0][0]; ?>

and here output both console , commandline:

console

"90.74" brewery.js:47 "90.29" brewery.js:47 "90.29" brewery.js:47 "89.39" brewery.js:47 "89.39" brewery.js:47 "89.39" brewery.js:47 "89.39" brewery.js:47 "89.39" brewery.js:47 "89.39" brewery.js:47 "89.61" brewery.js:47

command line

190.29pi@raspberrypi /var/www $ php temp0.php 190.40pi@raspberrypi /var/www $ php temp0.php 190.85pi@raspberrypi /var/www $ php temp0.php 191.08pi@raspberrypi /var/www $ php temp0.php 190.96pi@raspberrypi /var/www $ php temp0.php 190.29pi@raspberrypi /var/www $ php temp0.php 190.62pi@raspberrypi /var/www $ php temp0.php 190.18pi@raspberrypi /var/www $ php temp0.php 189.61pi@raspberrypi /var/www $ php temp0.php 189.39pi@raspberrypi /var/www $ php temp0.php

it seemed bit improve when slowed interval 1000 ms 2000 or 3000 ms, still wasn't consistent. run posted above interval set 2000, , never showed whole number.

javascript php jquery ajax

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -