vendredi 6 mars 2015

PHP: Echoing a JQuery Alert from case statement


Vote count:

0




I am trying to echo a JQuery alert from PHP. The method I am using is to echo the entire script tags and then the JQuery within it. JQuery is working because alerts elsewhere work. the JQuery library is loaded before the code i am trying so it is not that.


below is my current statement:



date_default_timezone_set('Europe/London'); #server timezone
$now = date('His'); #current time
$cl = '173000'; #closing time
$op = '084500'; #opening time

switch (true) {
case $now < $cl && $now > $op:
echo "open
<script type='text/javascript'>
$(document).ready(function(){
alert('open');
});
</script>
";
break;

case $now > $cl && $now < $op:
echo 'closed';
break;

default:
echo("neither closed nor open. dun dun duuuuun");
break;
}


I know the statement is working to some extent because the open string is displayed. I also see the script tags yet they don't seem to execute see below:




This image shows that the open text just before the script is echo'd into the page


The script is wrote into the page but not terminated




This image shows that the script tag is put into the page but is not executed


This is where the open text works



asked 1 min ago







PHP: Echoing a JQuery Alert from case statement

Aucun commentaire:

Enregistrer un commentaire