javascript - send data to the div tag only if the data is true -


i have ajax code gets time in seconds , pass div tag shown. thing is, want pass data div tag if pass if statement's test save space. example, want pass data div tag if seconds in less 30, if doesn't pass div tag, div tag shows null. instead of showing null, want stay @ 30 second mark without ajax function having pass data div tag. don't know if i'm saying makes sense you, if does, there way achieve i'm trying do? thanks.

testing1.php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>  <script type = "text/javascript">   function timeoutajax(url,id,timeout) {        $.ajax({            type: "post",            url: url,            error: function(xhr,status,error){alert(error);},            success:function(data) {              document.getelementbyid( id ).innerhtml = data;              settimeout(function() { timeoutajax(url,id,timeout); }, timeout);            }        });  }  timeoutajax("testing2.php","seconds",1000);  </script>  <div id = "seconds"></div> 

testing2.php

<?php  $date = date("s");  if ($date < 30){ echo $date; }  ?> 

i don't want below, because whole point of this, save space, , if echo anyway, passes data div tag. don't want pass data div tag if doesn't pass if statement, don't want input null, since happens if nothing passed div tag. there way keep div tag before?

testing2.php

<?php  $date = date("s");  if ($date < 30){ echo $date; } else { echo 30;}  ?> 

you can add else statement afterwards, echo 30. instead of setting nothing, null, can set 30.

if($date < 30){   echo $date; }else{   echo 30; } 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -